System information

Manual:Scripting-examples
40
Generate backup and send it by e-mail
This script generates backup file and sends it to specified e-mail address. Mail subject contains router's name, current
date and time.
Note that smtp server must be configured before this script can be used. See /tool e-mail for configuration
options.
Script:
/system backup save name=email_backup
/tool e-mail send file=email_backup.backup to="me@test.com" body="See attached file" \
subject="$[/system identity get name] $[/system clock get time] $[/system clock get date] Backup")
Note: backup file contains sensitive information like passwords. So to get access to generated backup file,
script or scheduler must have 'sensitive' policy.
Use string as function
Code:
:global printA [:parse ":local A; :put \$A;" ];
$printA
Check bandwidth and add limitations
This script checks if download on interface is more than 512kbps, if true then queue is added to limit speed to
256kbps.
Code:
:foreach i in=[/interface find] do={
/interface monitor-traffic $i once do={
:if ($"received-bits-per-second" > 0 ) do={
:local tmpIP [/ip address get [/ip address find interface=$i] address] ;
# :log warning $tmpIP ;
:for j from=( [:len $tmpIP] - 1) to=0 do={
:if ( [:pick $tmpIP $j] = "/") do={
/queue simple add name=$i max-limit=256000/256000 dst-address=[:pick $tmpIP 0 $j] ;
}
}
}
}
}