Send email about reboot

From MikroTik Wiki
Revision as of 15:35, 12 March 2012 by Davis (talk | contribs)
Jump to: navigation, search

This script is meant for being run on router startup (using scheduler). Script sends an email with time of router reboot and entire log once 90 seconds have been passed since initial time synchronization from NTP. Besides event about reboot is logged once time has been synchronized from NTP.

:while ( [:pick [/system clock get date] 7 11]<"2003" ) do={ :delay 10s }
/log info "time updated; uptime: $[/system resource get uptime]"
:local es "$[/system identity get name] rebooted on $[/system clock get date] $[/system clock get time]"
:delay 90s
:local eb "Log contents (with 90 seconds delay):\r\n"
:foreach le in=[/log print as-value] do={
  :set eb "$eb$[:pick [:tostr [:pick $le 1]] 5 100] $[:pick [:tostr [:pick $le 2]] 7 100]: $[:pick [:tostr [:pick $le 3]] 8 1000]\r\n"
/tool e-mail send to="" subject=$es body=$eb

This script helps to keep track of router reboots (e.g. of reboots caused by power interruptions).

NB Script has not been tested with logging to disk enabled. Also this script won't wait for time synchronization on any machine with real-time clock (e.g. x86 PC).

--Davis 12:12, 12 March 2012 (UTC)