Every Linux machine has jobs that need to run on a schedule: rotate a log, pull a backup, refresh a mirror, renew a certificate, clean a cache. For decades the answer was cron, and for a lot of those decades it was a good answer. But if you are on a modern distribution running systemd — which is to say almost all of them — you already have a scheduler that is more precise, gives you real logs, understands dependencies and does not care whether the machine was asleep at the appointed minute. It is the systemd timer, and once you have written one you rarely go back.
This guide covers what timers are, why they beat cron for most jobs, and how to build, run and debug your own — from the pair of unit files to reading the last run in the journal.
What a systemd timer actually is
A timer is not a script runner; it is a trigger. The work still lives in a normal .service unit. The .timer unit says when to start that service, and systemd does the rest: it starts the service, captures its output in the journal, tracks whether it is still running, and can skip a run or catch one up depending on how you configure it.
So a scheduled job is always a pair of files: one that describes the job, and one that describes the schedule. That separation feels like extra typing at first, and it is the thing that makes timers more powerful — the same service can be started by a timer, by a socket, by another unit, or by hand, and it behaves identically every time.
Why not just keep using cron
Cron is not broken, and for a one-liner on a machine you rarely touch it still works. But it has limits that bite exactly when a job matters:
| Problem with cron | How timers answer it |
|---|---|
| No logs by default; output goes to mail you never read | Everything lands in journalctl, with exit codes |
| If the machine was off at the scheduled time, the job is simply skipped | Persistent=true runs it once on the next boot |
| Runs overlap if the previous one is still going | systemd will not start a second copy of a running service |
| No dependency ordering, no resource limits | Full unit features: After=, Requires=, cgroup limits |
| Time zones and DST are a known mess | OnCalendar has an explicit timezone option |
The one thing cron still does more simply is a throwaway line you want to add and forget. For anything you will maintain, the timer wins.
Your first timer: a backup job
Let us build a real one. Suppose you have a script at /usr/local/bin/pull-backup.sh and you want it to run every night at 03:30. You write two files under /etc/systemd/system/.
First the service, pull-backup.service, which describes what runs:
[Unit]
Description=Nightly backup pull
[Service]
Type=oneshot
ExecStart=/usr/local/bin/pull-backup.sh
Type=oneshot is the right choice for a job that runs and exits rather than staying in the foreground. If your script is short, you can even skip the file and put the command inline in ExecStart=.
Then the timer, pull-backup.timer, which describes when:
[Unit]
Description=Run the backup pull every night
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
[Install]
WantedBy=timers.target
The [Install] section is what makes systemctl enable work: it tells systemd to pull this timer in with the rest of the timers at boot. Now arm it and confirm:
sudo systemctl daemon-reload
sudo systemctl enable --now pull-backup.timer
systemctl list-timers --all
daemon-reload is not optional after writing a new unit — without it systemd has not read your file yet. list-timers then shows the next scheduled run and the last one, and this is the command you will type more than any other.
OnCalendar: the schedule language
The one thing to learn is OnCalendar=, which uses a calendar spec that reads left to right as day-of-week, date, and time. Some examples you will reuse:
| Spec | Means |
|---|---|
*-*-* 03:30:00 |
Every day at 03:30 |
Mon..Fri *-*-* 09:00 |
Weekdays at 09:00 |
*-*-* 00/6:00:00 |
Every six hours |
weekly |
Once a week (shorthand) |
Mon *-*-1..7 04:00 |
First Monday of the month, 04:00 |
*-*-* *:0/15:00 |
Every fifteen minutes |
The shorthands minutely, hourly, daily, weekly, monthly, quarterly and yearly are accepted directly. Before you trust a spec, ask systemd to expand it for you:
systemd-analyze calendar "Mon..Fri *-*-* 09:00"
That prints the normalised form and the next few run times, which has saved more than one person from a schedule that fired at midnight instead of noon.
Monotonic timers: schedules that do not care about the clock
Not every job belongs to a wall-clock time. “Five minutes after boot” or “two hours after the last run” is often what you actually mean, and for that you use the monotonic options instead of OnCalendar:
[Timer]
OnBootSec=5min
OnUnitActiveSec=2h
OnBootSec counts from boot, OnUnitActiveSec from the last time the service ran, and OnStartupSec from when systemd itself started. These are immune to clock changes and time zones, so they are the right tool for keep-alive and polling jobs. You can mix a monotonic trigger with OnCalendar in the same timer if you want both a boot run and a nightly one.
Do not miss a run: Persistent and accuracy
Two settings turn a fragile schedule into a reliable one. Persistent=true is the important one: if the machine is powered off when the trigger is due, systemd runs the job once, shortly after the next boot. For a laptop that sleeps overnight, this is the difference between a backup that runs and one that silently never does.
[Timer]
OnCalendar=daily
Persistent=true
AccuracySec=1h
AccuracySec is the opposite lever: it tells systemd it may delay the job by up to an hour to batch it with other work and save power. The default is already one minute, which is why your timers may not fire at the exact second you wrote. Set AccuracySec=1s when a job genuinely needs to land on the mark.
Per-user timers
Timers are not only for root. Any user can have their own, and they run as that user with their own environment:
systemctl --user enable --now mytask.timer
systemctl --user list-timers
Drop the unit files in ~/.config/systemd/user/. The catch is that a user’s timers only run while that user has an active session, unless you enable lingering:
sudo loginctl enable-linger "$USER"
With lingering on, the user manager starts at boot and keeps the timers alive even when nobody is logged in. That is how you schedule a personal job on a desktop that you are not sitting at.
Debugging: where did my job go
When a timer does not do what you expect, work through it in order. First, is it even armed?
systemctl list-timers --all | grep pull-backup
Then read the unit’s own state and its recent journal:
systemctl status pull-backup.timer
systemctl status pull-backup.service
journalctl -u pull-backup.service -n 50 --no-pager
The journal entry is the whole point of moving off cron: you see the command, the start and stop times, the exit code, and whatever the script printed. To run the job right now without waiting for the schedule, start the service, not the timer:
sudo systemctl start pull-backup.service
And to check that systemd parsed your schedule correctly, go back to systemd-analyze calendar with the exact string from the unit file.
The mistakes that catch everyone once
- Forgetting
daemon-reload. New or edited units are invisible until you run it. Ifenablesays the unit does not exist, this is almost always why. - Enabling the service instead of the timer. You want
enable --now foo.timer. Enabling the service would run it once and never schedule it. - Expecting cron syntax.
0 3 * * *is not a validOnCalendar. Write it as*-*-* 03:00:00. - Assuming the exact second. Without a low
AccuracySec, systemd may delay a run by up to a minute. - Leaving a job in root’s crontab and a timer. If you migrate, delete the cron entry, or the job runs twice.
Should you migrate everything
No. A single machine with a handful of classic, well-understood cron jobs is not broken and does not need rescuing. Migrate the jobs that have ever surprised you: the backup that did not run because the laptop was closed, the script whose failure you only found out about weeks later, the task that overlapped itself. Those are exactly the jobs where the timer’s persistence, logging and dependency handling pay for the two extra files.
The mental shift is small and the payoff is large: you stop writing a schedule and hoping, and start describing a service and trusting systemd to run it — on time, with logs, and without doing it twice.
Sources
- systemd.timer — freedesktop.org: the full reference for every timer option used here.
- systemd.time — freedesktop.org: the calendar event syntax behind
OnCalendar. - systemd/Timers — Arch Wiki: a worked comparison of a cron job and its timer equivalent.





Leave a Reply