For details on scripting, consult respective manual
[admin@MikroTik] system script> add name=log-test source=:log [admin@MikroTik] system script> print 0 name="log-test" source=":log" owner=admin run-count=0 [admin@MikroTik] system script> .. scheduler [admin@MikroTik] system scheduler> add name=run-1h interval=1h script=log-test [admin@MikroTik] system scheduler> print Flags: X - disabled # NAME SCRIPT START-DATE START-TIME INTERVAL RUN-COUNT 0 run-1h log-test oct/30/2008 15:08:22 1h 1 [admin@MikroTik] system scheduler>
Argument description:
name - name of the task
start-time and start-date - time and date of first execution
interval - interval between two script executions, if time interval is set to zero, the script is only executed at it's start time, otherwise it is executed repeatedly at the time interval specified
run-count - to monitor script usage, this counter is incremented each time the script is executed, it can be reset to zero. Note that rebooting the router will reset this counter
script - name of the script. The script must be present at /system script.
Here are two scripts that will change the bandwidth setting of a queue rule "Cust0". Everyday at 9AM the queue will be set to 64Kb/s and at 5PM the queue will be set to 128Kb/s. The queue rule, the scripts, and the scheduler tasks are below:
[admin@MikroTik] queue simple> add name=Cust0 interface=ether1 dst-address=192.168.0.0/24 \
\... limit-at=64000
[admin@MikroTik] queue simple> print
Flags: X - disabled, I - invalid
0 name="Cust0" src-address=0.0.0.0/0 dst-address=192.168.0.0/24
interface=ether1 limit-at=64000 queue=default priority=8 bounded=yes
[admin@MikroTik] queue simple> /system script
[admin@MikroTik] system script> add name=start_limit source={/queue simple set Cust0 \
\... limit-at=64000}
[admin@MikroTik] system script> add name=stop_limit source={/queue simple set Cust0 \
\... limit-at=128000}
[admin@MikroTik] system script> print
0 name="start_limit" source="/queue simple set Cust0 limit-at=64000"
owner=admin run-count=0
1 name="stop_limit" source="/queue simple set Cust0 limit-at=128000"
owner=admin run-count=0
[admin@MikroTik] system script> .. scheduler
[admin@MikroTik] system scheduler> add interval=24h name="set-64k" start-time=9:00:00 \
\... script=start_limit
[admin@MikroTik] system scheduler> add interval=24h name="set-128k" start-time=17:00:00 \
\... script=stop_limit
[admin@MikroTik] system scheduler> print
Flags: X - disabled
# NAME SCRIPT START-DATE START-TIME INTERVAL RUN-COUNT
0 set-64k start... oct/30/2008 09:00:00 1d 0
1 set-128k stop_... oct/30/2008 17:00:00 1d 0
[admin@MikroTik] system scheduler>
The following setup schedules script that sends each week backup of router configuration by e-mail.
[admin@MikroTik] system script> add name=e-backup source={/system backup save name=email;
{... /tool e-mail send to="root@host.com" \
{... subject=[/system identity get name]" Backup" \
{... file=email.backup}
[admin@MikroTik] system script> print
0 name="e-backup" source="/system backup save name=ema... owner=admin
run-count=0
[admin@MikroTik] system script> .. scheduler
[admin@MikroTik] system scheduler> add interval=7d name="email-backup" script=e-backup
[admin@MikroTik] system scheduler> print
Flags: X - disabled
# NAME SCRIPT START-DATE START-TIME INTERVAL RUN-COUNT
0 email-... e-backup oct/30/2008 15:19:28 7d 1
[admin@MikroTik] system scheduler>
Do not forget to set the e-mail settings, i.e., the SMTP server and From: address under /tool e-mail. For example:
[admin@MikroTik] tool e-mail> set server=159.148.147.198 from=SysAdmin@host.com
[admin@MikroTik] tool e-mail> print
server: 159.148.147.198
from: SysAdmin@host.com
[admin@MikroTik] tool e-mail>
If more than one script has to be executed at one time, they are executed in the order they appear in the scheduler configuration. This can be important if, for example, one scheduled script is used to disable another. The order of scripts can be changed with the move command.
If a more complex execution pattern is needed, it can usually be done by scheduling several scripts, and making them enable and disable each other. Example below will put 'x' in logs each hour from midnight till noon:
[admin@MikroTik] system script> add name=enable-x source={/system scheduler enable x}
[admin@MikroTik] system script> add name=disable-x source={/system scheduler disable x}
[admin@MikroTik] system script> add name=log-x source={:log message=x}
[admin@MikroTik] system script> .. scheduler
[admin@MikroTik] system scheduler> add name=x-up start-time=00:00:00 interval=24h \
\... script=enable-x
[admin@MikroTik] system scheduler> add name=x-down start-time=12:00:00 interval=24h \
\... script=disable-x
[admin@MikroTik] system scheduler> add name=x start-time=00:00:00 interval=1h script=log-x
[admin@MikroTik] system scheduler> print
Flags: X - disabled
# NAME SCRIPT START-DATE START-TIME INTERVAL RUN-COUNT
0 x-up enable-x oct/30/2008 00:00:00 1d 0
1 x-down disab... oct/30/2008 12:00:00 1d 0
2 x log-x oct/30/2008 00:00:00 1h 0
[admin@MikroTik] system scheduler>