skip to Main Content

Tips4Tiks – Automating Scripts with Schedulers

Scripting and automation are perhaps the best time-saving joys of any programming language. MikroTik offers RouterOS’s built-in scripting language with a powerful set of commands to automate router tasks. These scripts can be bound and executed to an event, including the System Scheduler.

Scheduler can run scripts at regular intervals as well as execute three seconds after a router reboot. This is especially useful in routine router logging, configuring new DHCP gateways, and managing what time certain guest WiFi interfaces are available. If you can create a script for a job, the Scheduler can run it regularly.

System Scheduler Properties

Start Date & Start Time: Date and time of the first execution of the script, this is local to the router’s clock and timezone. You can check your system’s clock and settings with /system/clock/print.

Interval: The amount of time between script execution. By default, this is set to zero and the script is only executed once at the Start Date and Start Time. 

Startup: This property sets the Scheduler to run three seconds after startup instead of at a scheduled time or interval. When using startup Schedulers, the script will not run if the interval is set to anything other than zero.

Run Count: Counts the number of times the Scheduler has executed. Please note that rebooting the router will reset this counter.

On Event: This field can contain the script name or the script itself. For best practice, use the name of the script that is found at /system/script. 

Policy: Select applicable policies for your script, more information on each can be found here.

Next Run: On the Scheduler GUI window, the next time for the script to run is displayed.

Scheduler Example

Applications for Schedulers are as varied as the possible scripts! My first experience with Schedulers is in my own router lab for testing tasks. While I could simply run the cleanup script afterward manually, using the Scheduler to run the logs and remove redundant firewall rules and interfaces saved me a great deal of time.

Script example:

/ip firewall filter; :if ([:len [find where comment=”Allow_RWB_Firewall_test”]]>= 1) do={remove [find where comment=”Allow_RWB_Firewall_test”];};/ppp profile remove [find where name=”RemoteWinBoxTestProfile”];

With the GUI:

With the terminal:

/system scheduler add name=lab_cleanup interval=24h start-time=04:00:00 on-event=Lab_cleanup

We hope the Scheduler helps you with any regular, automated tasks to save you time!

For more scripting tips, check out our additional Fleet Commander Best Practices here.

Back To Top