I like cron, but I like even more being able to ask a machine when something will run next, and what it said the last time. A systemd timer answers both. It takes two small files instead of one line, and my advice is to use it for anything you actually care about, like a backup. This works on any current Linux with systemd (Ubuntu, Debian, Fedora); everything below runs as root, so adapt the paths if you want a user timer.
- Time
- 4 min
- Steps
- 6
- Updated
- 19 Nov 2026
You will learn
- The service file
- The timer file
- Check the schedule before you trust it
- Turn it on
- When it breaks
What you need
A script you want to run on a schedule. I use /usr/local/bin/backup.sh as a stand-in; the name backup is just an example, pick your own. Make sure it runs fine by hand first.
Step 1 of 6: The service file
A timer does not run your script itself. It starts a service, so write that first:
sudo nano /etc/systemd/system/backup.service
[Unit]
Description=Nightly backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
Type=oneshot tells systemd the job starts, does its work and ends. There is no [Install] section on purpose: the timer is what you enable.
Step 2 of 6: The timer file
Same name, .timer instead of .service. By default a timer starts the service with the matching name.
sudo nano /etc/systemd/system/backup.timer
[Unit]
Description=Run backup every night
[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
RandomizedDelaySec=5min
[Install]
WantedBy=timers.target
OnCalendar is the wall-clock schedule, here every day at 03:30. Persistent=true is the reason I would switch at all: systemd remembers when the service last ran, and if the machine was off at 03:30 it runs the job as soon as the timer is active again. Cron simply skips it. The systemd.timer manual says this only works for timers that use OnCalendar. RandomizedDelaySec spreads the start over a few minutes, which is nice if several machines hit the same NAS.
Step 3 of 6: Check the schedule before you trust it
Calendar expressions are easy to get slightly wrong, and there is a built-in checker. It prints the normal form and the next time it would fire:
systemd-analyze calendar "*-*-* 03:30:00"
You can also test the unit files for typos:
systemd-analyze verify /etc/systemd/system/backup.service /etc/systemd/system/backup.timer
Step 4 of 6: Turn it on
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
Enable the .timer, not the .service. Now look at the result:
systemctl list-timers backup.timer
The columns show when it fires next, how long that is from now, and when it last ran. That one command is my favourite part. To test the job without waiting for the night, start the service by hand:
sudo systemctl start backup.service
journalctl -u backup.service -e
Everything the script printed ends up in the journal, with timestamps, and systemctl status backup.service shows whether the last run ended in success or failure. With cron you would have had to set up mail or a log file yourself.
Step 5 of 6: When it breaks
If list-timers shows nothing, you probably forgot daemon-reload or enabled the wrong unit. If the service fails but works in your shell, the usual cause is the environment: a service does not get your PATH or your home directory, so use full paths in the script and set User= in the service if it must not run as root. For one-off schedules the OnCalendar format also takes things like Mon..Fri 08:00. The calendar checker from step 3 will tell you what any of these means.
Step 6 of 6: Should you move everything?
No. A crontab line is still the quickest way to run something trivial. I would move the jobs where a missed run, a log or a start time matters, which for me means backups and cleanups on a server. In the Netherlands the clock changes twice a year, and a timer handles that without you thinking about it, since the time zone rules come from the system.
Further reading
- systemd.timer manual
- systemd.time manual (calendar syntax)
- systemd-analyze manual
- On this site: Keep passwords out of your Docker Compose file
- On this site: Docker Compose healthchecks, and how to see why a container is unhealthy
- On this site: Make Docker Compose wait until the database is really ready, not just started
