systemd Timers: The Cron Replacement That Tells You When It Failed

Cron runs your job and forgets it. systemd timers log every run, catch up after the machine was off, and spread the load so twenty servers don't all back up at 2:00 sharp.

Tux Harlow

3 min read

Cron is wonderful. It's been running jobs since the 1970s, and its five little fields are lodged in every sysadmin's brain. But cron has a habit: it runs your job, throws the output at a mailbox nobody reads, and forgets about it. systemd timers do the same work, remember what happened, and tell you about it.

If your machine runs systemd (most distros do), you already have everything you need.

Two files instead of one line

A cron job is one line. A systemd timer is two small files: a service that says what to run, and a timer that says when.

Say you have a nightly backup script. Create /etc/systemd/system/backup.service:

INI
[Unit]
Description=Nightly backup

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh

Then create /etc/systemd/system/backup.timer next to it:

INI
[Unit]
Description=Run the nightly backup

[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
RandomizedDelaySec=15m

[Install]
WantedBy=timers.target

Matching names matter: backup.timer starts backup.service automatically. Switch it on:

Bash
sudo systemctl daemon-reload
sudo systemctl enable --now backup.timer

Yes, it's more typing than cron. Here's what the extra lines buy you.

The three lines cron can't do

Persistent=true remembers the last run. If the laptop was asleep at 2:30, the job runs as soon as it wakes. Cron just skips it and says nothing.

RandomizedDelaySec=15m starts the job at a random moment up to fifteen minutes late. On one machine that doesn't matter. On twenty machines sharing one backup server, it's the difference between a calm night and a stampede at 2:30:00.

Type=oneshot tells systemd the job runs and then exits. systemd tracks it while it runs, so a second copy can't start while the first is still going. In cron, avoiding that overlap is a flock trick you have to remember yourself.

See what's scheduled

Bash
systemctl list-timers

You get a neat table: when each timer runs next, how long until then, when it last ran, and which service it triggers. Compare that with crontab -l for every user on the box and trying to work out the next run in your head.

Read what happened

This is the best part. Everything your script prints goes to the journal:

Bash
journalctl -u backup.service
journalctl -u backup.service --since today

Did it fail? Check:

Bash
systemctl status backup.service

It shows the exit code, the last run and the last few log lines. A failed run marks the unit as failed, and monitoring can watch for that with a single command: systemctl --failed.

Test your schedule before trusting it

Cron syntax is famous for "wait, does that mean every minute?". systemd will check the expression for you:

Bash
systemd-analyze calendar "Mon..Fri 09:00"
  Original form: Mon..Fri 09:00
Normalized form: Mon..Fri *-*-* 09:00:00
    Next elapse: Mon 2026-11-16 09:00:00 PST

A few forms worth knowing:

  • daily, weekly and hourly work as you'd guess.
  • *-*-* 02:30:00 means every day at 2:30.
  • Sat *-*-1..7 10:00 means the first Saturday of every month at 10:00.
  • *:0/15 means every fifteen minutes.

A one-off, no files needed

Want something to run once, in half an hour? Skip the unit files:

Bash
systemd-run --on-active=30m /usr/local/bin/backup.sh

It's like at, except it's already installed and it logs to the journal.

Should you migrate everything?

No need. Cron still works, and a one-line job on a personal box is fine where it is. Move the jobs that matter: backups, certificate renewals, anything that would hurt if it quietly stopped. Those are the ones where "it logs every run and says when it failed" is worth a second file.

Your 2:30 a.m. self will appreciate it.