I have the following script and it works very well for me, every time the electricity is cut off it tells me in a file.txt the date and time the service was cut off.
:global stopRouterRun false;
:do {
:local file "electric cut.txt";
:local day ([:pick [/system clock get date] 4 6]);
:local mon ([:pick [/system clock get date] 0 3]);
:local year ([:pick [/system clock get date] 7 11]);
:local date "$day-$mon-$year";
:local time (:put [/system clock get time]);
:local data1 (" court: " . $date . " at: " . $time . " ) ;
/file print file="$file"
/file set $file contents=$data1;
:delay 60;
} while=(!$stopRouterRun)
I would like you to help me with a script that records in a .txt file, the time when the electrical service was restored,
but it should be taken into account that every time the electricity arrives, the internet does not arrive at the same time,
I do not know if you understand me Thanks for your help, especially Rextended and Jotne.
Thanks for assisting me Rextended, but I need a script that creates a file.txt for me to know at what time the electrical service was restored in my RB, I hope you understand me.
Rextended, the script is overwriting the file, what I want is for it to tell me at what time the electricity was restored, and from there it stops, Wouldn't it be better to do a subtraction of the hour minus the uptime, I don't know.
Do you understand me?
the script keep history of shutdown (every time the script is launched…)
the file is never deleted, last bootup is added on top
do some operations, like subtract minutes, is useless, everytime the routerboard is started 120s + 3s before the date inside the script.
Why do not correct it?
For example 00:00 - 2min and 3 sec = -23:57:57, not the date of previous day, but a negative time value…
:delay 120s
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
{
:local ndate [/system clock get date]
:local now "$[:pick $ndate 7 11]-$($arrMonths->[:pick $ndate 0 3])-$[:pick $ndate 4 6]_$[/system clock get time]"
:local shutname "booted_$now.txt"
/file
:if ([:len [find where name="flash" and type="disk"]] = 1) do={:set shutname "flash/$shutname"}
:if ([:len [find where name=$shutname]] = 0) do={print file=$shutname; :delay 5s; set $shutname contents=""}
}
Every time the router is powered (and after 120s for make internet available and time sincronized)
a file name booted_2022-04-06_19:42:23.txt is created.
do not deplete the space because the file is empty. (really use ~64byte for each filename)
Now it is creating many files, Rextended.
What I am saying is that for example we have the next time 14:10:00, and the uptime is 01:03:00, make a file for me and say that the equipment booted 13:07:00,
you understand me friend.
Why continuosly run the script?
The boot time is still the same…
Is useless every minute do the calc and write it on file, the boot time is the exact same value…
the equipment booted everytime at 13:07:00
Is better you explain what you want do at the end, instead of ask about intermediate process, because often I do not understand you…
I want to make a script that writes me a file.txt, where it says at what time the RB booted and leaves it like that, but we have to take into account that the internet does not arrive all at once, that's why I say that it is better to execute it every 10 minutes , you understand me friend Rextended.
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
{
:local filename "firsttimesync.txt"
/file
:if ([:len [find where name="flash" and type="disk"]] = 1) do={:set filename "flash/$filename"}
:if ([:len [find where name=$filename]] = 0) do={print file=$filename}
:delay 5s
set $filename contents="undefined"
:do { :delay 1s } while=([:typeof [/system ntp client get last-update-before]] != "time")
:local ndate [/system clock get date]
:local now "$[:pick $ndate 7 11]-$($arrMonths->[:pick $ndate 0 3])-$[:pick $ndate 4 6] $[/system clock get time]"
set $filename contents=$now
}
What do: at startup replace previous datetime with “undefined”, then wait until time is syncronized for first time from routerboard boot,
and write inside the file firsttimesync.txt the date and time of that moment.
Any more execution is useless.
Subtracting uptime from that datetime for obtain the precise date and time of boot is another thing…
With my script you have a great approximation when the RouterBOARD is for the first time online after (re)boot
And the value is close to last boot datetime