Cron vs Systemd Timers: Which One Should You Use?
Cron and systemd timers both run a job on a schedule. The difference is everything that happens around the run: what gets logged, what happens after downtime, and what happens when the previous run is still busy.
What cron gives you
Cron is a single line in a single file:
30 2 * * * /usr/local/bin/backup.sh
It runs on almost every Unix-like system, including containers and minimal images that carry nothing else. The file is easy to read, easy to copy between machines, and easy to keep in version control. For a small, fast, self-contained job, nothing beats it.
What cron does not give you: a record of whether the job worked, a retry, or a warning when two copies overlap. It starts the command and walks away.
What a systemd timer adds
A systemd timer is a pair of files: a service that describes the job, and a timer that describes when to start it.
- Every run has a status.
systemctl status backup.servicesays active, failed, or still running, with the exit code. Logs go to the journal:journalctl -u backup.service. - Missed runs can be caught up.
Persistent=truemakes the timer run once after boot if the machine was off when the schedule fired. - The same job cannot run twice. If the previous run of a oneshot service is still going, the next start is skipped. That single rule kills the classic cron problem of stacked copies.
- Dependencies and limits exist.
After=network-online.targetwaits for the network.CPUQuota=andMemoryMax=cap the job.RandomizedDelaySec=spreads load across a fleet. - The schedule is testable.
systemctl list-timers --allshows the next and last run for every timer on the machine.
What they cost
- Two files per job, plus
systemctl daemon-reloadafter every edit. OnCalendar=is its own small syntax:Mon..Fri 09:00,*-*-* 02:30:00,hourly.- Not every environment runs systemd. Minimal containers and some embedded systems do not.
The overhead is real, and for a five-line script it can be more ceremony than the job deserves.
Side by side
| Question | Cron | Systemd timer |
|---|---|---|
| Setup | one line, one file | two files, reload |
| Logs | syslog line at start only | journald: start, output, exit code |
| Missed run after downtime | lost | caught up with Persistent=true |
| Overlap protection | none | the unit cannot run twice |
| Retry on failure | none | Restart= on the service |
| Dependency ordering | none | After=, Requires= |
| Portability | nearly universal | systemd systems only |
| Environment | minimal shell environment | explicit Environment= lines |
How to choose
- A quick script on any machine, especially a container: cron. The line is the documentation.
- A job that must not be missed: systemd timer with
Persistent=true. A laptop, a home server, or a VM that reboots for updates will silently skip cron runs, and you will not notice until someone asks for the report. - A job whose output you will need to read later: systemd timer. The journal keeps stdout and stderr without any redirect tricks.
- A job that must not overlap: systemd timer. With cron you build a lock file yourself.
- A job that needs more than one command in order: systemd, where
After=replaces a sleep loop and a pile of comments.
A simple rule that holds up: cron for conveniences, timers for obligations.
Moving a job from one to the other
The conversion is mostly mechanical, but three things do not translate by substitution:
- The either-or day rule. A cron line that restricts both day of month and day of week fires on either match.
OnCalendar=has no such quirk, so the converted timer will run less often. Split the schedule into two timers if you truly need both. @reboot. There is no exact twin.OnBootSec=1minwith a timer is the usual approximation, but it runs on every boot, not only after a reboot event you chose.- The environment. Cron gives the job almost nothing: a minimal
PATH,SHELL=/bin/sh, andHOME. A converted job that suddenly cannot find a binary usually fails because the timer’s environment is different again. Write the absolute paths and theEnvironment=lines down instead of guessing.
Check the result with systemctl list-timers --all: the NEXT column is the honest answer to “is it armed?”.
Switch without a gap
If the job matters, run the new timer beside the old cron line for a week, with the same schedule but a harmless action, and compare the timestamps. When the two agree, delete the cron line.
The converter takes a crontab line and produces the OnCalendar= form, with the cases it cannot express listed rather than silently dropped. The systemd guide covers the unit files in full, and the parser helps when you are unsure what the original cron line meant in the first place.