Basic Scheduler and Scripts
Basic Scheduler and Scripts
Section titled âBasic Scheduler and ScriptsâTL;DR (Quick Start)
Section titled âTL;DR (Quick Start)âFor the impatient: hereâs the 30-second version.
# Create and schedule a daily backup script/system script add name=daily-backup source="/system backup save name=auto-backup"/system scheduler add name=daily-backup-job start-time=00:00:00 interval=1d on-event=daily-backupOverview
Section titled âOverviewâThis guide demonstrates how to create scripts and schedule them on MikroTik RouterOS for automated tasks.
Prerequisites
Section titled âPrerequisitesâ- A MikroTik router running RouterOS 7.x or later
- Access to the router via SSH, WinBox, or WebFig
Configuration Steps
Section titled âConfiguration StepsâStep 1: Create a Simple Logging Script
Section titled âStep 1: Create a Simple Logging ScriptâCreate a script that logs the current date and time:
/system script add name=log-time source=":log info \"Scheduled check at \$[/system clock get time]\"" comment="Time logging script"Step 2: Create a Backup Script
Section titled âStep 2: Create a Backup ScriptâCreate a script that generates a configuration backup:
/system script add name=daily-backup source="/system backup save name=auto-backup" comment="Daily backup script"Step 3: Schedule the Logging Script
Section titled âStep 3: Schedule the Logging ScriptâSchedule the logging script to run every hour:
/system scheduler add name=hourly-log interval=1h on-event=log-time comment="Run log-time every hour"Step 4: Schedule the Backup Script
Section titled âStep 4: Schedule the Backup ScriptâSchedule daily backup at midnight:
/system scheduler add name=daily-backup-job start-time=00:00:00 interval=1d on-event=daily-backup comment="Daily backup at midnight"Verification
Section titled âVerificationâCheck 1: Scripts
Section titled âCheck 1: Scriptsâ/system script printExpected Output:
Flags: I - invalid # NAME OWNER POLICY RUN-COUNT LAST-STARTED 0 log-time admin read,write 5 jan/17/2026 14:00:00 1 daily-backup admin read,write 1 jan/17/2026 00:00:00Check 2: Scheduler
Section titled âCheck 2: Schedulerâ/system scheduler printExpected Output:
Flags: X - disabled # NAME START-DATE START-TIME INTERVAL ON-EVENT 0 hourly-log jan/17/2026 00:00:00 1h log-time 1 daily-backup-job jan/17/2026 00:00:00 1d daily-backupCheck 3: Test Script Execution
Section titled âCheck 3: Test Script Executionâ/system script run log-time/log print where message~"Scheduled check"Troubleshooting
Section titled âTroubleshootingâProblem: Script not running
Section titled âProblem: Script not runningâSymptoms: Scheduled task never executes, no log entries.
Causes & Solutions:
-
Syntax errors in script - Test script manually:
/system script run log-timeIf error appears, fix the script source.
-
Scheduler disabled - Check scheduler status:
/system scheduler printLook for X (disabled) flag. Enable if needed.
-
Wrong script name in scheduler - Verify on-event matches script name exactly.
Problem: Script runs but nothing happens
Section titled âProblem: Script runs but nothing happensâSymptoms: Script executes (run-count increases) but expected action doesnât occur.
Causes & Solutions:
-
Permission issues - Check script policy:
/system script print detail where name=daily-backupEnsure script has required policies (read, write, policy, test, etc.)
-
Variable scope issues - Local variables donât persist. Use global for cross-script data.
-
Silent errors - Add logging to script for debugging:
:log info "Script started"# ... commands ...:log info "Script completed"
Problem: Script timing is wrong
Section titled âProblem: Script timing is wrongâSymptoms: Script runs at unexpected times.
Causes & Solutions:
-
System clock wrong - Verify NTP is configured:
/system clock print/system ntp client print -
Start-time not set - For specific times, set both start-time and interval:
/system scheduler set daily-backup-job start-time=00:00:00 -
Timezone issues - Check timezone setting:
/system clock print
Problem: Backup files not created
Section titled âProblem: Backup files not createdâSymptoms: Backup script runs but no files appear.
Causes & Solutions:
-
Disk full - Check available space:
/file print/system resource print -
Path issues - Verify file destination:
/file print where name~"backup" -
Filename collision - Use unique names with date:
/system script set daily-backup source=":local date [/system clock get date]; /system backup save name=(\$date . \"-backup\")"
Related Topics
Section titled âRelated TopicsâCommon Scripting Use Cases
Section titled âCommon Scripting Use Casesâ- System Backup - automate backups
- DHCP Server - lease notifications
- Netwatch - failover scripts
Related System Topics
Section titled âRelated System Topicsâ- Logging - log script activity
- Email Tool - send notifications from scripts
- User Management - script permissions
Monitoring
Section titled âMonitoringâ- Torch - traffic monitoring via scripts
- Resource Monitoring - CPU/memory checks