Its intention is to write the date and time to the clock.txt file on disk.
It will record this time every 3 minutes
If by chance the equipment is restarted
It will check the uptime, if it is less than 5 minutes, it will go to else, and will not record the current time in the crock.txt file
instead it will take the time of this file and save it in a variable, it will also compare if there is any message in the log containing "Router was rebooted", then it will send an email, informing the last registration time, the current time and an account of how long the equipment was turned off.
Code: Select all
/system scheduler add name=Test-Rebooted start-time=startup interval=00:03:00 on-event="
:local date
:local time
:local day
:local month
:local year
:local clock
:local timeoff
:local clocktime
delay 120s;
if ([/system/resource/get uptime] > 00:05:00) do={
:local day1
:local month1
:local year1
:local newdate [/system clock get date]
:local newtime [/system clock get time]
:local clock "clock.txt"
:set day1 [:pick $newdate 4 6];
:set month1 [:pick $newdate 0 3];
:set year1 [:pick $newdate 7 11];
/file print file="$clock"
:local newfilecontent "$day1/$month1/$year1, $newtime"
/file set $clock contents=$newfilecontent
} else={
:local clock [/file get [/file find name=clock.txt] contents];
if ([:len [/log find message~"Router was rebooted"]] != 0) do={
:set date [/system clock get date];
:set time [/system clock get time];
:set day [:pick $date 4 6];
:set month [:pick $date 0 3];
:set year [:pick $date 7 11];
:set clocktime [:pick $clock 13 21]
:set timeoff ($time - clocktime)
/tool e-mail send to=email@email.com subject="$[/system identity get name] - Router was rebooted - Time off: $timeoff" body="$clock, $[/system identity get name] - Time the router was rebooted
$day/$month/$year, $time, $[/system identity get name] - Time router turned on
Time off: $timeoff" file=clock.txt tls=starttls
}
}
"