Cron has scheduled jobs on Linux for decades, and for a one-line job it is still hard to beat. But the moment a job matters — a nightly backup, a cleanup script, a report your team actually reads — cron’s silence becomes a problem. You find out a job failed when something downstream breaks, not when it happens. systemd timers fix that: they turn a scheduled job into a proper unit with logs, status, and failure handling, for roughly the same effort as a crontab line. This guide migrates one real cron job to systemd timers, step by step, and covers the options you will actually reach for afterwards.
Why cron starts to hurt
Cron’s model is a line in a table: five time fields and a command. That simplicity is also its ceiling. Four rough edges show up on real servers:
- No run history. Cron does not record whether last night’s job ran, how long it took, or what it exited with. Unless you redirected output yourself, there is nothing to inspect.
- Output goes to a black hole. Whatever a job prints is either mailed to a local mailbox nobody reads, or lost. You only learn about failures indirectly.
- Missed runs are just skipped. If the machine was off at 02:30, cron does not run the 02:30 job later. A separate tool, anacron, can catch up daily jobs, but it is not part of cron itself and it cannot express “at 02:30”.
- A stripped-down environment. Cron runs with a minimal PATH and almost no environment variables, which is why a script that works in your shell mysteriously fails under cron.
A systemd timer does not have these problems, because the job runs as a normal systemd service. Its output lands in the journal, systemctl status shows its last result, and you can run it on demand without waiting for the schedule.
A systemd timer is two files
This is the one idea to hold onto. A timer is not a single config file; it is a pair of unit files that share a name:
- The service (
.service) says what to run. It holds the command, the user, and any sandboxing or environment. - The timer (
.timer) says when to run it. It holds the schedule and the reliability options.
By default, a timer named backup.timer activates a service named backup.service — same stem, different extension. You only need the Unit= setting in the timer if you want it to trigger a differently named service. The service needs no [Install] section, because you never enable the service directly; you enable the timer, and the timer attaches itself to boot through WantedBy=timers.target.
System units live in /etc/systemd/system/. That is where the examples below go. If you do not have root, skip ahead to the user-timers section — the same pair of files works under ~/.config/systemd/user/.
Your first systemd timer, step by step
Take a concrete cron job and move it across. Suppose your crontab currently has this line:
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
Step one is the service file, /etc/systemd/system/backup.service:
[Unit]
Description=Nightly database backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
Type=oneshot is the right type for a job that runs and exits, rather than a long-running daemon. Note what is missing: there is no output redirect. The script’s stdout and stderr go to the journal automatically, so the >> /var/log/backup.log 2>&1 tail of the cron line is no longer needed.
Step two is the timer file, /etc/systemd/system/backup.timer:
[Unit]
Description=Run the nightly backup at 02:30
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
[Install]
WantedBy=timers.target
Step three is to load the new units and enable the timer — the timer, not the service:
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
You must run daemon-reload after creating or editing any unit file, or systemd will keep using the old version. The --now flag both enables the timer for future boots and starts it immediately; without it, the timer would only take effect after the next boot.
Step four is to prove it works before you trust it. Run the service by hand, outside the schedule:
sudo systemctl start backup.service
sudo systemctl status backup.service --no-pager
journalctl -u backup.service --since today
If that run succeeds, check the timer itself:
systemctl list-timers --all | grep backup
systemctl status backup.timer --no-pager
list-timers shows the next and last trigger times, which is the answer to “when does this run next?” that cron never gave you. Only once you have seen a successful scheduled run should you delete the old crontab line. Run the two side by side for a day if the job is critical — a duplicate backup is a much cheaper mistake than a missing one.
Reading OnCalendar without guessing
OnCalendar= is systemd’s wall-clock schedule. Its grammar is weekday, then year-month-day, then hour:minute:second, and any field can be * to match everything, a comma-separated list, or a range written with ... The weekday is optional and uses English day names, such as Mon or Monday. If you omit the date, *-*-* is implied; if you omit the time, midnight is implied.
Most cron schedules translate mechanically:
| Cron line | Meaning | OnCalendar |
|---|---|---|
30 2 * * * |
02:30 every day | *-*-* 02:30:00 |
0 * * * * |
Top of every hour | hourly |
*/15 * * * * |
Every 15 minutes | *:0/15 |
0 4 * * 1 |
04:00 every Monday | Mon *-*-* 04:00:00 |
30 22 * * 1-5 |
22:30 on weekdays | Mon..Fri 22:30 |
0 0 1 * * |
Midnight on the 1st | monthly |
systemd also provides shorthands, and these are worth memorising: minutely, hourly, daily (midnight), weekly (Monday at midnight), monthly (the 1st at midnight), quarterly, and yearly. A timer can carry more than one OnCalendar= line, and it fires whenever any of them matches.
Never commit a schedule you have not dry-run. Cron has no equivalent of this, and it is one of the best reasons to switch:
systemd-analyze calendar '*-*-* 02:30:00'
systemd-analyze calendar 'Mon..Fri 22:30' --iterations=5
The command confirms the expression parses and prints the next times it will fire. If the output does not match what you intended, fix the expression before the timer ever runs.
One accuracy surprise to know about: timers do not necessarily fire at the exact second you wrote. AccuracySec= defaults to one minute, which means systemd may place the firing anywhere inside a one-minute window starting at your scheduled time, deliberately coalescing timer events to avoid unnecessary wake-ups. For a nightly backup that is irrelevant. For a job that must fire at an exact second, set AccuracySec=1us — and accept the extra wake-ups that come with it.
Three systemd timers you will actually use
1. The daily job with a safety net
The backup timer above is the template for most jobs: OnCalendar= plus Persistent=true. The next section explains Persistent in detail; for now, treat it as the default for daily jobs on machines that are not always on.
2. The frequent job that should not stampede
A cleanup script that runs every 15 minutes looks like this:
[Unit]
Description=Clean up stale session files every 15 minutes
[Timer]
OnCalendar=*:0/15
AccuracySec=1us
RandomizedDelaySec=5min
[Install]
WantedBy=timers.target
RandomizedDelaySec= delays the firing by a random amount between zero and the value you give, so a fleet of machines running the same timer does not hammer a shared server at the same instant. It defaults to zero, meaning no delay. Note the pairing: when you combine it with AccuracySec=, the randomised delay is applied first and the result may then be shifted again to coalesce with other timer events — so if you genuinely want the spread, set AccuracySec=1us as above, otherwise the coalescing can undo it.
3. The job measured from boot, not from the clock
Some jobs are relative, not calendar-based: run five minutes after boot, then every hour after the job last ran. That is a monotonic timer, and it needs no OnCalendar= at all:
[Unit]
Description=Refresh the local cache after boot and hourly thereafter
[Timer]
OnBootSec=5min
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target
OnBootSec= fires relative to boot, and OnUnitActiveSec= fires relative to the last time the service itself was activated. Cron’s closest equivalent is @reboot plus a sleep hack, and it cannot express “every hour since the last run” at all. Monotonic timers reset on reboot, which is the behaviour you want for a cache refresh and the wrong behaviour for a job that must run at a wall-clock time — use OnCalendar= for those.
Missed runs: Persistent=true, and when not to use it
Persistent=true is the feature that most directly answers cron’s biggest weakness. When it is set, systemd stores the last trigger time on disk. If the timer was inactive at a scheduled time — the machine was off, for example — the service is triggered immediately when the timer is activated again, which in practice means at the next boot. The missed run happens once, not once per missed slot.
Three caveats keep this honest. First, Persistent= only has an effect on timers configured with OnCalendar=; it does nothing for monotonic timers. Second, a brand-new persistent timer with no recorded trigger can fire once immediately after you enable it, because systemd treats the never-run state as a missed slot — do not be surprised by one immediate run, and do not mistake it for a bug. Third, catch-up is not always what you want. A daily newsletter job that fires a day late is worse than one that skips a day, and a job that sends notifications should not send yesterday’s alerts this morning. For those, leave Persistent off (it defaults to false) and let the missed run stay missed.
When the job fails, hear about it
systemd has no built-in equivalent of cron’s MAILTO. Nothing emails you when a timer job fails, and pretending otherwise would be dishonest. What it does give you is OnFailure=: a setting on the service that activates another unit when the service enters the failed state. The smallest useful version logs an alert into the journal at error priority, where whatever already watches your logs will see it.
Add this to the job’s service file:
[Unit]
Description=Nightly database backup
OnFailure=notify-failed@%n.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
And create one reusable template, /etc/systemd/system/notify-failed@.service:
[Unit]
Description=Log a failure for %i
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo "ALERT: %i failed on $(hostname), see: journalctl -u %i" | systemd-cat -t failure-alert -p err'
%n in the first file expands to the failing unit’s own name, which becomes the template’s argument; %i in the template picks that argument back up. One template therefore serves every job on the box. You can then read failures with journalctl -t failure-alert, or swap the echo | systemd-cat line for a curl call to your alerting service. If you genuinely need email, the same pattern works with a small script that calls mailx — but you need a working mail setup on the server first, and that is a separate project, not a timer feature.
Systemd timers without root
Everything above assumed system units, but you can run timers as an ordinary user with no root at all. Put the same pair of files in ~/.config/systemd/user/ and manage them with the --user flag:
mkdir -p ~/.config/systemd/user
systemctl --user daemon-reload
systemctl --user enable --now backup.timer
systemctl --user list-timers --all
The catch is session lifetime: by default, user timers only run while you are logged in. If you log out, they stop. To keep them running after logout — and to start them at boot even when you are not logged in — enable lingering for your account, which does need root once:
sudo loginctl enable-linger $USER
Without lingering, a user timer on a laptop or a shared box will silently stop the moment you disconnect. That is the single most common “my timer worked yesterday” mystery, and it is worth checking before you debug anything else.
Troubleshooting checklist
When a timer does not fire, work through this list in order:
- Did you enable the timer, or the service? Enabling the service does nothing on a schedule.
systemctl list-timersshould show your timer; if it does not, it was not enabled. - Did you reload? Every create or edit needs
systemctl daemon-reload. A stale unit file is the most boring and most common cause. - Is the service failing instantly? A timer that fires a broken service looks dead. Run
systemctl start backup.serviceby hand and readjournalctl -u backup.service— the crash will be there. - Are you checking the right status?
systemctl status backup.timershows the timer as active even while it is idle between runs.list-timersis the command that shows next and last runs. - Is the schedule what you think it is? Re-run
systemd-analyze calendaron your expression, and remember the default one-minuteAccuracySec=window — a job that fires a few seconds “late” is behaving as configured. - Is the timezone what you think it is?
OnCalendar=uses the system timezone by default. A server on UTC and a developer thinking in local time will disagree by hours, not minutes. - Is it a user timer without lingering? See the previous section. If it worked while you were logged in and stopped afterwards, this is almost certainly it.
When to keep cron
Timers are the better default on a modern systemd machine, but cron still wins in three places. First, brevity: one crontab -e line beats two unit files for a throwaway job you will delete next week. Second, portability: cron is the only scheduler guaranteed to exist on minimal containers and non-systemd systems, so a script that must run everywhere should stay a cron job. Third, machines you did not set up yourself: if you are dropping a job onto a box you do not administer, the existing cron setup is the one the next person will look for. The honest rule is to use systemd timers for anything you own on a systemd system, and keep cron for one-line jobs and boxes outside that world.
Migration checklist
- Pick the cron job you worry about most — usually the backup — and migrate that one first.
- Write the service and timer, validate the schedule with
systemd-analyze calendar, and test the service by hand withsystemctl start. - Enable the timer, confirm the next run in
list-timers, and watch one scheduled run succeed in the journal. - Only then delete the crontab line. For critical jobs, let both run side by side for a day first.
- Add
Persistent=truewhere a missed run matters,OnFailure=where silence would hurt, and lingering if the timer belongs to a user account. - Repeat for the next job. Migrating one job properly teaches you more than converting ten in a hurry.
Cron earned its long life by being simple and predictable. systemd timers keep the predictability and add the three things cron never had: a log you can actually read, a status you can actually check, and a missed run that does not quietly vanish. That is a trade worth two small files.
Further Reading & References
- systemd.timer(5) — Timer unit configuration (man page)
- systemd.time(7) — Time and date specifications, including OnCalendar shorthands
- Replacing Your Cron Jobs With systemd Timers — OpenReplay Blog
- Cron to systemd timers: a practical migration guide for Linux — DEV Community
- Stop Writing Cron Jobs. Use a systemd Timer. — DEV Community
- Cron vs systemd timers: which should you use? — DEV Community
- A Beginner’s Guide to systemd Timers (2026) — OSTechNix
- Master systemd Timers: A Complete Cron Alternative Guide — LinuxTeck
Related on HowToShipIt: How to Set Up Automated VPS Backups, WordPress Cron Is Fake: How to Disable WP-Cron and Set Up Real Cron, and How to Set Up Fail2ban on Ubuntu.



