Scheduling scripts: cron, systemd timers and Windows Task Scheduler
In short: Scheduled scripts turn one-off checks into routine automation. On Linux use cron or systemd timers; on Windows use Task Scheduler. Always use full paths, run as a least-privilege account, capture output to a log and test the job before relying on it.
Why schedule scripts
A backup script that you must remember to run is not really automation. Scheduling lets the operating system start your script at fixed times, at boot or when an event happens. Typical jobs include nightly configuration backups, hourly reachability checks, weekly certificate expiry reports and log clean-up.
cron on Linux
Edit your own schedule with crontab -e and list it with crontab -l. Each line has five time fields and a command.
# m h dom mon dow command
15 2 * * * /opt/netops/backup_configs.sh >> /var/log/netops/backup.log 2>&1
*/10 * * * * /opt/netops/reach_check.sh /opt/netops/core.txt
0 7 * * 1 /usr/bin/python3 /opt/netops/cert_report.py
The first job runs at 02:15 every day and appends both output and errors to a log. The second runs every ten minutes. The third runs at 07:00 every Monday. If you are unsure of a time expression, write it in a comment in plain English next to the line.
cron runs jobs with a very small environment: a short PATH, no aliases and no interactive profile. That is the number one reason a script works by hand and fails under cron. Use full paths to commands and files, or set PATH at the top of the crontab.
systemd timers
On modern distributions a systemd timer is a good alternative. It is two small files: a .service unit that runs the script and a .timer unit that says when. Output goes to the journal automatically, and Persistent=true runs a missed job after the machine was switched off.
# /etc/systemd/system/netbackup.timer
[Unit]
Description=Nightly network config backup
[Timer]
OnCalendar=*-*-* 02:15:00
Persistent=true
[Install]
WantedBy=timers.target
Enable it with systemctl enable --now netbackup.timer, check it with systemctl list-timers and read output with journalctl -u netbackup.service.
Windows Task Scheduler
A scheduled task has a trigger (when), an action (what to run) and a principal (which account). You can build it in the GUI or with PowerShell, which is easier to repeat across servers.
$action = New-ScheduledTaskAction -Execute 'pwsh.exe' `
-Argument '-NoProfile -File "C:\Scripts\Check-Servers.ps1"'
$trigger = New-ScheduledTaskTrigger -Daily -At 6:45am
Register-ScheduledTask -TaskName 'NetOps-DailyCheck' -Action $action `
-Trigger $trigger -User 'NT AUTHORITY\SYSTEM' -RunLevel Highest
For tasks that need network access to other servers, use a group Managed Service Account (gMSA) or a dedicated low-privilege service account instead of a personal login, so the task does not break when someone changes their password or leaves.
- Run the script by hand as the same account the scheduler will use.
- Use full paths and write output to a log file.
- Make the script exit non-zero on failure and alert on it.
- Check the first few scheduled runs in the log or task history.
Tip: stagger heavy jobs (for example 02:15 instead of 02:00) so dozens of jobs do not all hit the network and storage at the same minute.
Practice
What does the cron line "0 7 * * 1" mean?
Why does a script often work by hand but fail in cron?
Why use a service account or gMSA for a scheduled task?
Key takeaways
- cron uses five time fields followed by a command.
- Use full paths and redirect output to a log.
- systemd timers add journal logging and catch-up runs.
- Task Scheduler jobs have a trigger, an action and a run-as account.
- Run scheduled jobs under dedicated least-privilege accounts.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.