Cron and systemd timers both run a command on a schedule. Cron is one line in a crontab and works the same on every Unix system. A systemd timer takes two small files, and in exchange you get logs in the journal, missed runs caught up after downtime, no overlapping runs and second level precision.
Side by side
| cron | systemd timer | |
|---|---|---|
| Setup | One crontab line | Two unit files |
| Smallest step | 1 minute | 1 second |
| Output | Mailed, or a file you redirect to | In the journal |
| Machine off at run time | The run is skipped | Can run at the next boot |
| Previous run still going | A second copy starts | Nothing starts until it ends |
| Random start delay | By hand, with sleep | Built in |
| Time zone | The system's | Per timer |
| CPU and memory limits | None | Any systemd limit |
| Next run times | Not shown | Shown by list-timers |
The same job both ways
A backup script every day at 3:00. With cron:
0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
With systemd, first the service, in /etc/systemd/system/backup.service:
[Unit]
Description=Nightly backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
Then the timer, with the same name, in /etc/systemd/system/backup.timer:
[Unit]
Description=Run the nightly backup
[Timer]
OnCalendar=*-*-* 03:00:00
Persistent=true
[Install]
WantedBy=timers.target
Load and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
Enable the .timer, not the .service. The timer starts the service with the same name; Unit= in the timer points it at another one. To run the job once by hand: sudo systemctl start backup.service.
OnCalendar next to cron
The format is weekday year-month-day hour:minute:second, and each part can be left out or written as *.
| Schedule | cron | OnCalendar |
|---|---|---|
| Every 15 minutes | */15 * * * * | *:0/15 |
| Every hour | 0 * * * * | hourly |
| Every day at 3:00 | 0 3 * * * | *-*-* 03:00:00 |
| Weekdays at 9:00 | 0 9 * * 1-5 | Mon..Fri 09:00 |
| Mondays at midnight | 0 0 * * 1 | weekly |
| 1st of the month | 0 0 1 * * | monthly |
A time zone goes at the end, like *-*-* 03:00:00 Europe/Paris. Cron has no per job time zone, except CRON_TZ on cronie.
Two traps. weekly in systemd is Monday, while @weekly in cron is Sunday. quarterly means every three months. To check an expression and see when it runs next:
systemd-analyze calendar "Mon..Fri 09:00"
For the cron side, the cron expression tester shows the next runs, and crontab syntax covers every field.
Timer options worth knowing
Persistent=truestores the last run on disk. If the machine was off when a run was due, the job runs right after the next boot.AccuracySec=1smakes the job start on the second. The default of 1 minute lets systemd start it up to a minute late, to group wakeups.RandomizedDelaySec=10minadds a random delay up to that value, so 50 servers don't all run the job at the same second.OnBootSec=5minruns the job once, 5 minutes after boot.OnUnitActiveSec=1hruns it 1 hour after the last start, wherever that falls on the clock. Combine it withOnBootSec=for a job that repeats from boot.MemoryMax=andCPUQuota=in the.servicecap what the job can use.
Check and debug
| Task | Command |
|---|---|
| Next and last run of every timer | systemctl list-timers |
| State of one timer | systemctl status backup.timer |
| Output of the job | journalctl -u backup.service |
| Output since this morning | journalctl -u backup.service --since today |
| Find a failed run | systemctl --failed |
The cron side of this is in cron logs and list cron jobs.
Which one to use
Keep cron when the job is simple, the machine is always on or the same crontab has to work on systems without systemd (Alpine and most containers, the BSDs, macOS). On Kubernetes, use a CronJob instead of either. Switch to a timer when a missed run matters after downtime, when a slow run must never overlap the next one, when you want the output in the journal with the rest of the system, or when the job needs a memory or CPU cap.
Get an alert when it stops
A failed run shows in systemctl --failed, but nobody gets told, and a timer that was never enabled after a rebuild shows nothing at all. Add a heartbeat ping in the service. ExecStartPost= only runs when ExecStart= succeeded:
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
ExecStartPost=curl -fsS -m 10 -X POST https://api.failover.io/heartbeat/<your-monitor-id>
With cron, the same ping goes after &&. When a ping is late, you get an alert. See how to monitor cron jobs.
Frequently asked questions
Are systemd timers better than cron?
For jobs on a server that runs systemd, usually: logs in the journal, missed runs caught up with Persistent=true, and no overlapping runs. Cron is simpler and works on systems without systemd.
How do I list systemd timers?
Run systemctl list-timers. Add --all to include inactive timers.
What is the systemd equivalent of a cron job every 5 minutes?
OnCalendar=*:0/5 in the timer. Check it with systemd-analyze calendar "*:0/5".
Does a systemd timer run a missed job after a reboot?
Only with Persistent=true in the [Timer] section, and only for OnCalendar= timers. The default is false.
Can a systemd timer run every 30 seconds?
Yes, with OnCalendar=*:*:0/30 and AccuracySec=1s. Without the second line, runs can start up to a minute late.