System information

Manual:Scripting-examples
43
:global lastTime;
:global currentBuf [ :toarray [ /log find buffer=pppoe ] ] ;
:global currentLineCount [ :len $currentBuf ] ;
:global currentTime [ :totime [/log get [ :pick $currentBuf ($currentLineCount -1) ] time ] ];
:global message "";
:if ( $lastTime = "" ) do={
:set lastTime $currentTime ;
:set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
} else={
:if ( $lastTime < $currentTime ) do={
:set lastTime $currentTime ;
:set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
}
}
After new entry is detected, it is saved in "message" variable, which you can use later to parse log message, for
example, to get pppoe clients mac address.
Allow use of ntp.org pool service for NTP
This script resolves the hostnames of two NTP servers, compares the result with the current NTP settings and
changes the addresses if they're different. This script is required as RouterOS does not allow hostnames to be used in
the NTP configuration. Two scripts are used. The first defines some system variables which are used in other scripts
and the second does the grunt work:
# System configuration script - "GlobalVars"
:put "Setting system globals";
# System name
:global SYSname [/system identity get name];
# E-mail address to send notifications to
:global SYSsendemail "mail@my.address";
# E-mail address to send notifications from
:global SYSmyemail "routeros@my.address";
# Mail server to use
:global SYSemailserver "1.2.3.4";
# NTP pools to use (check www.pool.ntp.org)
:global SYSntpa "0.uk.pool.ntp.org";
:global SYSntpb "1.uk.pool.ntp.org";