Complex Logging script

Hi, What I want is:
I’m using Mikrotik 2.9.x
I want it to create a .txt file in every 6 hours. File should be named as a ‘date’ and hour name.
Also, I want to
log print file thatdateandhour.txt
That command will be work in every 6 hours. That should use same file as mikrotik create that .txt file.

How can I do that?

sorry, cant test this code in 2.9.x I made it in 3.14..


:local varDate;
:local varMonth;
:local varDay;
:local varYear;
:set varDate [/system clock get date];
:set varMonth [:pick $varDate 0 3];
:set varDay [:pick $varDate 4 6];
:set varYear [:pick $varDate 7 11];
log print append file=([$varMonth]."-".[$varDay]."-".[$varYear]."-".[/system clock get time])

This script wil print log to a file with filename month-day-year-time.txt
Schedule it to run every 6 hour and youre done.
I had to format the date strings or it wouldnt be accepted as a file name because of the /'s

There’s no code like log print append file in mt 2.9.x I guess so I made it:

:local varDate;
:local varMonth;
:local varDay;
:local varYear;
:set varDate [/system clock get date];
:set varMonth [:pick $varDate 0 3];
:set varDay [:pick $varDate 4 6];
:set varYear [:pick $varDate 7 11];
log print file=([$varMonth]."-".[$varDay]."-".[$varYear]."-".[/system clock get time])

Guess It will no make problem.

I clicked Run Script.
It didn’t create a file.
When I try the script that I give, There’s a number adding in ‘Run Count’
but when I clicked your script, there’s no number adding in Run Count so it always has been 0.

this should work (but only gives you a timestamp on the file)
-this is the only code you need, remove the rest


log print file=([/system clock get time])
[admin@MikroTik] > :local varDate;
[admin@MikroTik] > :local varMonth;
[admin@MikroTik] > :local varDay;
[admin@MikroTik] > :local varYear;
[admin@MikroTik] > :set varDate [/system clock get date];
[admin@MikroTik] > :set varMonth [:pick $varDate 0 3];
[admin@MikroTik] > :set varDay [:pick $varDate 4 6];
[admin@MikroTik] > :set varYear [:pick $varDate 7 11];
[admin@MikroTik] > log print file=([$varMonth]."-".[$varDay]."-".[$varYear]."-".
[/system clock get time])
invalid expression

this is mine

[admin@MikroTik] > :local varDate;
[admin@MikroTik] > :local varDate;
[admin@MikroTik] > :local varMonth;
[admin@MikroTik] > :local varDay;
[admin@MikroTik] > :local varYear;
[admin@MikroTik] > :set varDate [/system clock get date];
[admin@MikroTik] > :set varMonth [:pick $varDate 0 3];
[admin@MikroTik] > :set varDay [:pick $varDate 4 6];
[admin@MikroTik] > :set varYear [:pick $varDate 7 11];
[admin@MikroTik] > log print append file=([$varMonth]."-".[$varDay]."-".[$varYea
r]."-".[/system clock get time])
invalid expression
no such argument (append)

this is yours.

yes I know… use the line in my previous post.

It just saves the time. I need also date.

You will not be able to use date in format as ‘/system clock get date’ is giving it out as file name ( / symbol is not allowed in filenames).
You have to replace all ‘/’ symbols with, for example ‘-’.

try this. I tested it, it works.

:global thisdate [/system clock get date]

:global thistime [/system clock get time]

:global datetimestring ([:pick $thisdate 7 11] . [:pick $thisdate 0 3] . [:pick $thisdate 4 6] . “-” . [:pick $thistime 0 8])

/log print file $datetimestring