Automate Unitrunker2 log generation on Windows 10 (HOW-TO)

Ozzychaser

Member
Joined
Apr 28, 2014
Messages
16
Location
Adelaide
Hello,

I thought I would share my method on how I get log files automatically generated from Unitrunker2.

Open the Unitrunker folder (C:\Users\NUC\AppData\Roaming\Unitrunker) - Replace 'NUC' with the name used on your PC

Create a folder called Logs

--

Open windows Powershell ISE (just use the search box on the task bar). When it opens, in the white area type: (Again replace NUC with the name used on your PC)

cd C:\Users\NUC\AppData\Roaming\Unitrunker
move-item -path output.Log -destination C:\Users\NUC\AppData\Roaming\Unitrunker\Logs
cd C:\Users\NUC\AppData\Roaming\Unitrunker\Logs
$dt_str = (Get-Date).AddDays(-1).ToString('dd-MM-yyyy')
DIR output.Log | Rename-Item -NewName { $dt_str + ".Log" + $_name -replace "output","" }

Save this as C:\UTLogscript.ps1

You may have to save the UTLogscript.ps1 file to your desktop etc first then copy it to the C:\ and click Continue to provide administrator permission to move the file

---

Open windows powershell (again use the search box) and at the PS C:\WINDOWS\system32> prompt type:

Set-ExecutionPolicy RemoteSigned

If you get a warning about protecting you from scripts you do not trust - Press "A"

(Note: I run this on a system isolated from any outside connections etc and is only a dedicated radio PC)

-----

Open Task Scheduler (again from the search box)

On the Left hand panel create a folder called Unitrunker,

Right click on the folder and select create basic task

Name: UTLogCreate
Description: Unitrunker Log Creator
Click Next
Select Daily
Click Next
Your Start date will be dependent on when you set this up, but I set it to the next day (- setup the scripts etc on the 20th so set it to start on the 21st etc)
Start time: 12:02:00 AM
Recur every: 1 days
Click Next
Select Start a program
Click Next
In Program/script: C:\Windows\System32\cmd.exe
Arguments: /c pushd "%APPDATA%\Unitrunker" & "C:\Program Files\Unitrunker\Excavate" yesterday APCOP25 id=BEE003DC >output.Log (Some of these arguments SYS ID etc will change depending on the system you are monitoring. Please see the website here for more information on the Excavate program arguments http://unitrunker.com/v2/excavate.html)
Click Next
Click Finish

-------------

Right click on the Unitrunker folder again and select Create basic Task again

Name: Move & Rename UTLogs
Description: Moves and Renames Unitrunker Log Files
Click Next
Select Daily
Click Next
Your Start date will be dependent on when you set this up, but I set it to the next day (- setup the scripts etc on the 20th so set it to start on the 21st etc)
Start time: 12:03:00 AM (Set 1 minute later than log file creation)
Recur every: 1 days
Click Next
In Program/script: powershell.exe
Arguments: ". 'C:\UTLogscript.ps1' "
Click Next
Click Finish

--------

You can incrementally test that the different parts outlined above are working by using the command line to make sure your excavate command arguments are correct and then using powershell to execute the script as follows &"C:\UTLogscript.ps1"

If all works well you will end up with a file such as 31-05-2023.Log (provided you tried this on 1 June 2023) in your Logs directory and of course a new one created each day. The dd-MM-yyyy string can be changed to alter the formatting if you wish.

The link above explaining the arguments that can be used with Excavate has a lot of detail and I would recommend you having a look if log files are of interest to you.

I have read through this a couple of times and cannot spot any spelling or syntax mistakes and I have this working on Windows10, I know there are some differences with other versions of windows so I don't know if it will work for them.

If anyone else wants to give this a try, please let me know how you go.

Please note that automatic log file generation is not a standard part of the program and it is only a work around that I have put together for my use and thought others may find it helpful. If you have any issues please don't hesitate to ask here and I will help if I can, however I am only new to powershell script's (less than a week).

James.
 

Ozzychaser

Member
Joined
Apr 28, 2014
Messages
16
Location
Adelaide
No problems @sonm10, I tried using a .bat file to start with also and while that worked to generate the initial output.Log expanding it to move and rename the file got messy and didn't end up working. I don't think the math required to subtract a day really works well in .bat files..
 
Top