hello guys, you can make a .txt file to record the time the routerboard was started for the first time with the following data:
Date: Apr/17/2022
Time: 13:10:10
Uptime: 1d 00:09:20
Thanks for your help.
EL DONCITO:
Try this:hello guys, you can make a .txt file to record the time the routerboard was started for the first time with the following data:
Date: Apr/17/2022
Time: 13:10:10
Uptime: 1d 00:09:20
Thanks for your help.
EL DONCITO:
:local newdate [/system clock get date]
:local newtime [/system clock get time]
:local newuptime [/system resource get uptime]
:local filename "infosystem.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=""}
:delay 5s
:local filecontent [get $filename contents]
:local newfilecontent "Info: $newdate\t$newtime\t$newuptime\r\n$filecontent"
set $filename contents=$newfilecontent
Info: apr/19/2022 18:06:50 5d04:52:13
Info: apr/19/2022 18:06:40 5d04:52:03
Info: apr/19/2022 18:06:25 5d04:51:48
Info: apr/19/2022 18:06:02 5d04:51:26
You will have to get in your WAN interface -> Status, the date in the "Last Link UP Time" field in a global variable.Thanks friend, but it is not what I need, what I need is that according to the uptime, you can give me the information at what time the routerboard reboot.
/file remove [find where name="testfetch.txt"]
{
# seconds of timeout, after that time stop try get the time from url
:local timeout 120
:local jobid [:execute file=testfetch.txt script="/tool fetch url=\"http://worldclockapi.com/api/json/vst/now\""]
:put "\r\nWaiting the end of process for file testfetch.txt to be ready, max $timeout seconds..."
:global Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < $timeout)) do={
:set Gltesec ($Gltesec + 1)
:delay 1s
:put "waiting... $Gltesec"
}
:put "Done. Elapsed Seconds: $Gltesec\r\n"
:if ([:len [/file find where name="testfetch.txt"]] = 1) do={
:local filecontent [/file get [/file find where name="testfetch.txt"] contents]
:put "Result of Fetch:\r\n****************************\r\n$filecontent\r\n****************************"
:if ([:len [/file find where name="now"]] = 1) do={
:local filecontent [/file get [/file find where name="now"] contents]
:put "\r\nFile content:\r\n****************************\r\n$filecontent\r\n****************************"
} else={
:put "\r\nURL not reached."
}
} else={
:put "Generic error, Test file not created."
}
}
/file remove [find where name="testfetch.txt"]
{
# seconds of timeout, after that time stop try get the time from url
:local timeout 120
:local jobid [:execute file=testfetch.txt script="/tool fetch url=\"http://worldclockapi.com/api/json/vst/now\""]
:put "\r\nWaiting the end of process for file testfetch.txt to be ready, max $timeout seconds..."
:local Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < $timeout)) do={
:set Gltesec ($Gltesec + 1)
:delay 1s
:put "waiting... $Gltesec"
}
:put "Done. Elapsed Seconds: $Gltesec\r\n"
:if ([:len [/file find where name="testfetch.txt"]] = 1) do={
:local filecontent [/file get [/file find where name="testfetch.txt"] contents]
:put "Result of Fetch:\r\n****************************\r\n$filecontent\r\n****************************"
:if ([:len [/file find where name="now"]] = 1) do={
:local filecontent [/file get [/file find where name="now"] contents]
:put "\r\nFile content:\r\n****************************\r\n$filecontent\r\n****************************"
:local dstart ([:find $filecontent "currentDateTime\":\"" -1] + 18)
:local year [:pick $filecontent $dstart ($dstart + 4)]
:local month [:pick $filecontent ($dstart + 5 ) ($dstart + 7)]
:local day [:pick $filecontent ($dstart + 8 ) ($dstart + 10)]
:local hm [:pick $filecontent ($dstart + 11 ) ($dstart + 16)]
:put "\r\nTime readed from the URL: $year-$month-$day $hm\r\n"
} else={
:put "\r\nURL not reached."
}
} else={
:put "Generic error, Test file not created."
}
}
/file remove [find where name="testfetch.txt"]
{
:local filename "lastupurl.txt"
# seconds of timeout, after that time stop try get the time from url
:local timeout 120
:local jobid [:execute file=testfetch.txt script="/tool fetch url=\"http://worldclockapi.com/api/json/vst/now\""]
:put "\r\nWaiting the end of process for file testfetch.txt to be ready, max $timeout seconds..."
:local Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < $timeout)) do={
:set Gltesec ($Gltesec + 1)
:delay 1s
:put "waiting... $Gltesec"
}
:put "Done. Elapsed Seconds: $Gltesec\r\n"
:if ([:len [/file find where name="testfetch.txt"]] = 1) do={
:local filecontent [/file get [/file find where name="testfetch.txt"] contents]
:put "Result of Fetch:\r\n****************************\r\n$filecontent\r\n****************************"
:if ([:len [/file find where name="now"]] = 1) do={
:local filecontent [/file get [/file find where name="now"] contents]
:put "\r\nFile content:\r\n****************************\r\n$filecontent\r\n****************************"
:local dstart ([:find $filecontent "currentDateTime\":\"" -1] + 18)
:local year [:pick $filecontent $dstart ($dstart + 4)]
:local month [:pick $filecontent ($dstart + 5 ) ($dstart + 7)]
:local day [:pick $filecontent ($dstart + 8 ) ($dstart + 10)]
:local hm [:pick $filecontent ($dstart + 11 ) ($dstart + 16)]
:put "\r\nTime readed from the URL: $year-$month-$day $hm\r\n"
/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=""}
:delay 5s
:local newfilecontent "Date: $year-$month-$day\r\nTime: $hm\r\nUptime: $[/system resource get uptime]"
set $filename contents=$newfilecontent
} else={
:put "\r\nURL not reached."
}
} else={
:put "Generic error, Test file not created."
}
/file remove [find where name="testfetch.txt"]
/file remove [find where name="now"]
}
{
:local filename "lastupurl.txt"
:local timeout 60
:local url "http://worldtimeapi.org/api/timezone/America/Caracas.txt"
/file
remove [find where name="fetchtest.txt"]
remove [find where name="fetchnow.txt"]
:local jobid [:execute file=fetchtest.txt script="/tool fetch url=\"$url\" dst-path=fetchnow.txt"]
:local Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < $timeout)) do={:set Gltesec ($Gltesec + 1); :delay 1s}
:if ([:len [find where name="fetchnow.txt"]] = 1) do={
:local filecontent [get [find where name="fetchnow.txt"] contents]
:local dstart ([:find $filecontent "datetime: " -1] + 10)
:local year [:pick $filecontent $dstart ($dstart + 4)]
:local month [:pick $filecontent ($dstart + 5 ) ($dstart + 7)]
:local day [:pick $filecontent ($dstart + 8 ) ($dstart + 10)]
:local hms [:pick $filecontent ($dstart + 11 ) ($dstart + 19)]
: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=""}
:delay 5s
:global arrMonths {"01"="ENE";"02"="FEB";"03"="MAR";"04"="ABR";"05"="MAY";"06"="JUN";\
"07"="JUL";"08"="AGO";"09"="SEP";"10"="OCT";"11"="NOV";"12"="DIC"}
:local mhours [:tonum [:pick $hms 0 2]]
:local minsec [:pick $hms 2 8]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
set $filename contents="Date: $($arrMonths->$month)/$day/$year\r\nTime: $mhours$minsec $msymbl\r\n\
Uptime: $[/system resource get uptime]"
}
remove [find where name="fetchtest.txt"]
remove [find where name="fetchnow.txt"]
}
Date: ABR/20/2022 Time: 04:49:23 AM Uptime: 00:02:26
{
:local filename "lastupurl.txt"
:local timeout 60
:local url "http://worldtimeapi.org/api/timezone/Etc/UTC.txt"
/file
remove [find where name="fetchtest.txt"]
remove [find where name="fetchnow.txt"]
:local jobid [:execute file=fetchtest.txt script="/tool fetch url=\"$url\" dst-path=fetchnow.txt"]
:local Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < $timeout)) do={:set Gltesec ($Gltesec + 1); :delay 1s}
:if ([:len [find where name="fetchnow.txt"]] = 1) do={
:local filecontent [get [find where name="fetchnow.txt"] contents]
:local dstart ([:find $filecontent "datetime: " -1] + 10)
:local year [:pick $filecontent $dstart ($dstart + 4)]
:local month [:pick $filecontent ($dstart + 5 ) ($dstart + 7)]
:local day [:pick $filecontent ($dstart + 8 ) ($dstart + 10)]
:local hms [:pick $filecontent ($dstart + 11 ) ($dstart + 19)]
: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=""}
:delay 5s
set $filename contents="Date: $year-$month-$day\r\nTime: $hms\r\nUptime: $[/system resource get uptime]"
}
remove [find where name="fetchtest.txt"]
remove [find where name="fetchnow.txt"]
}
Date: 2022-04-20 Time: 08:49:23 Uptime: 00:02:26