Display router downtime by script

Hi,
I have a requirement that I want to know when router reboots, it should ECHO in LOG that when was last time router rebooted or powered off and how much time it was off by comparing it with current date/time.

Example the script should show in LOGs as following

Router last reboot (Value-A) : xx-date-time
Powered back on (Values-B): xx-date-time
Total downtime difference in hours between values A &B) : ???

I have idea that script can create a variable of last online time and update time in it after very minute, and when router reboots, it should get this value and calculate with current time value and also shows the downtime in hours (or days). I know how can I get value-a and value-B, but how to calculate difference of time in between both values to show in hours and if its in days it should days/hours ?

is it possible ?

Well yes you can do this but would require some scripting i would separate the values first basically get data hours minutes ect each into their own variable then convert each to seconds so if you do this for your two date time samples you should have two seconds values which you can then subtract and get the difference in seconds you can then convert the seconds back to hours


Sent from my iPhone using Tapatalk

How can I print Specific Environment value only?
Example I have script which updates an environemtn variable with current date time, now i want to print this variable only (without other details.
for example if i try to get value from varibale it shows 3 lines and then in logs it doens’t show any thing i want only VALUE

print value where name=Lastseen
user: admin
name: Lastseen
value: 13:32:47 jun/14/2015

I want to show value only

Try this

:local lastseen [/system script environment get [/system script environment find name="Lastseen"] value];
:log warning $lastseen;

Result will appear in LOG window in blue color. or you can use the result in your email or whatever is required. I will post little script for you once i will be in the office

actually what i want is to see the last tie when was router ok. so something like lastseen value and the current one on RB. so i can calculate difference for how long the RB was down.

I don’t know much about Routeros Scripting, but by seeing this link, http://wiki.mikrotik.com/wiki/Send_email_about_reboot , we can modify it work for your environment. but you have to create two scripts for it, one which will keep updating the date+time in a local file (to preserve it on reboot) and the second script which will trigger on next reboot.
Taking idea from the above link, modified version of that script along with the second script can be found here.
https://aacable.wordpress.com/2015/06/15/sending-email-on-router-reboot-with-logs-and-lastseen-time/

Don’t know how , but it worked perfectly :slight_smile: Thank You All ! :slight_smile:

How can I display total time of downtime? example above script shows only from - till time, how can i show lets say “router was down for 36 hours” or “router was down for 1 day 16 hours”?