Who this is for

You have things in a crontab. They mostly work. Someone told you systemd timers are better and you’re not sure whether that’s true or just newer.

Short version: timers are better for anything that matters, cron is better for anything that doesn’t, and the migration is easier than it looks.

The problem

cron has been scheduling jobs on Unix since 1975 and it is still installed nearly everywhere. That’s not an accident — it’s five lines of config and it works.

But cron was designed for a world where a scheduled job printed to a terminal and mailed you if it failed. On a modern server that model leaks in specific, annoying ways:

  • Your job’s output goes to an email nobody reads, or nowhere at all.
  • If the machine was off at 3am, the 3am job simply didn’t happen.
  • Every job on the box fires at exactly 0 3 * * *, all at once.
  • The job inherits almost no environment, and finding out which almost is a rite of passage.
  • Two long-running copies can overlap and you’ll never know.

systemd timers address all five. They also cost you two files instead of one line.

Quick answer

The difference comes down to what each tool knows about the job it started.

cron is one line in a crontab. It runs your command at a time, and that is the whole contract. It does not know whether the job finished, whether it is still running from last time, or whether the machine was asleep when the moment passed. Output goes to mail, which on most modern boxes means it goes nowhere. If you want to stagger a job across twenty machines, you write a sleep $RANDOM at the top of the script yourself.

A systemd timer costs you two unit files instead of one line, and buys you everything cron does not track. Output lands in the journal, so journalctl -u yourjob is the whole answer to “what happened.” Persistent=true catches up runs the machine slept through. It will not start a second copy while the first is still going. RandomizedDelaySec= spreads the load without a hack in your script. You get After= and Requires= so the job waits for the database to be up, and you get cgroup limits so a runaway job cannot eat the box. systemctl list-timers answers “did it run, and when is the next one” without opening your inbox. Timers can also schedule relative to events — OnBootSec=, OnUnitActiveSec= — which cron simply cannot express.

What cron keeps is reach and speed of learning. It is on every Unix, including minimal containers and BSD, and you can teach it in ten minutes. A timer takes an afternoon.

Use a timer when: the job matters, needs logging, must catch up after downtime, or depends on something else being up.

Stay on cron when: it’s a personal one-liner, you’re on a non-systemd box or a minimal container, or the job genuinely does not matter.

Step-by-step: convert a crontab line to a timer

Here’s a typical crontab entry:

30 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

Nightly at 03:30, output appended to a log file you then have to rotate yourself.

1. Write the service unit

The timer says when. The service says what. You need both.

/etc/systemd/system/backup.service:

[Unit]
Description=Nightly backup
After=network-online.target
Wants=network-online.target

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

Type=oneshot is the key difference from a long-running service. It means “run this to completion, then you’re done” — systemd considers the unit active only while it runs, and doesn’t treat exiting as a failure.

Note there’s no [Install] section and no Restart=. You never enable this service directly; the timer starts it.

Also note there’s no output redirection. stdout and stderr go to the journal automatically. Delete the log file and the logrotate config while you’re here.

2. Write the timer unit

/etc/systemd/system/backup.timer:

[Unit]
Description=Run nightly backup at 03:30

[Timer]
OnCalendar=*-*-* 03:30:00
Persistent=true
RandomizedDelaySec=300
Unit=backup.service

[Install]
WantedBy=timers.target

The name matters: backup.timer automatically triggers backup.service. The Unit= line is only needed if the names differ, but writing it out is clearer.

Persistent=true is the big one. If the machine was off at 03:30, the job runs as soon as it comes back up. cron just skips it.

RandomizedDelaySec=300 spreads the actual start over a five-minute window. On one box that’s mild politeness. On fifty boxes hitting the same backup target, it’s the difference between a thundering herd and a working backup.

3. Enable the timer, not the service

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

Enabling backup.service instead is the classic mistake — it runs the job immediately at boot and never again.

4. Check it

systemctl list-timers

This is the command that makes timers worth it. One table showing every timer, when it last ran, when it next fires, and how long until then. There is no cron equivalent; with cron you read the crontab and do the arithmetic in your head.

systemctl list-timers --all        # including inactive ones
systemctl status backup.timer      # the timer
systemctl status backup.service    # the last run's result
journalctl -u backup.service       # everything it has ever logged

5. Test the job without waiting for 03:30

sudo systemctl start backup.service

Runs it right now, on demand, logged the same way. Doing this with cron means either editing the schedule to two minutes from now, or running the script by hand in an environment that doesn’t match cron’s.

Understanding OnCalendar

The syntax is DayOfWeek Year-Month-Day Hour:Minute:Second. Anything you leave out defaults to “every”.

OnCalendar=*-*-* 03:30:00           # daily at 03:30
OnCalendar=Mon..Fri *-*-* 09:00     # weekdays at 09:00
OnCalendar=*-*-01 00:00:00          # first of every month
OnCalendar=*-*-* *:0/15             # every 15 minutes
OnCalendar=Sat *-*-* 02:00          # Saturdays at 02:00
OnCalendar=hourly                   # shorthand
OnCalendar=daily
OnCalendar=weekly

You do not have to guess. Test any expression before you ship it:

systemd-analyze calendar "Mon..Fri *-*-* 09:00"

It prints the normalised form and the next few times it will fire. I use this every single time — it has caught more of my mistakes than anything else in this post.

The relative schedules cron cannot do

OnBootSec=15min              # 15 minutes after boot
OnUnitActiveSec=6h           # 6 hours after the last run finished
OnStartupSec=1h              # 1 hour after systemd itself started

OnUnitActiveSec is genuinely useful and has no cron equivalent. “Every six hours” in cron means at 00:00, 06:00, 12:00, 18:00. If your job takes 90 minutes, the gap between runs is 4.5 hours, not 6. OnUnitActiveSec=6h means six hours after the previous one finished, which is usually what you actually meant.

Where cron still wins

I don’t want to oversell this. cron is genuinely the right answer sometimes.

Containers and minimal images. Many don’t run systemd at all. cron or a simple supervisor loop is the correct tool.

Non-systemd systems. Alpine, BSD, some embedded distros.

Personal one-liners. crontab -e, one line, done. Two unit files for “sync my notes every hour” is real overhead for no real gain.

Ubiquity. Every sysadmin alive can read a crontab. Not everyone can read a timer unit yet.

And a genuine annoyance with timers: two files per job. For fifteen scheduled jobs that’s thirty files, versus one crontab you can read top to bottom. There’s no way around that, and it’s a real cost when you’re skimming a machine you’ve never seen.

What neither tool fixes

This is the part most comparisons skip, and it’s the part that has actually bitten me.

A scheduled job that dies partway through can leave no trace. I once chased a job that “wasn’t running.” It was running, every night, on time. What was failing was the chain of work it kicked off — it died partway through and the failure looked exactly like a quiet night with nothing to do.

Three lessons from that, and none of them are about cron or systemd:

Alert on the absence of success, not just the presence of failure. If your only signal is a “job completed” notification, then a job that dies before it can report anything is indistinguishable from a job that had nothing to do. That’s a dead-man’s switch, and you have to build it deliberately.

Know what happens when the job is killed. If your work is chained — each run queuing the next — then a crash doesn’t cost you one run, it costs you the entire remaining chain. Retry limits matter enormously here, and the default is often zero.

Watch the input volume, not just the job. The job that broke had not changed in months. What changed was an unrelated setting upstream that multiplied its nightly workload by 25. Nothing in the scheduler will tell you that.

Timers help with the first of these — systemctl list-timers shows you the last run time, and the journal keeps the output — but you still have to look. A timer that fails silently every night looks fine until someone checks.

The one thing a timer gives you free that cron doesn’t: overlap protection. If a run is still going when the next one is due, systemd won’t start a second copy. With cron you need your own lock file, and the number of scripts I’ve seen with a broken lock file is not small.

Common mistakes

Enabling the .service instead of the .timer. The single most common one. systemctl enable --now backup.timer.

Forgetting Persistent=true. Your laptop was asleep, so the job never ran, and you don’t find out until you need the backup.

Using Type=simple for a one-shot job. Use Type=oneshot. With simple, systemd considers the unit finished the moment the process starts, which makes list-timers and overlap protection lie to you.

Assuming the environment. Same trap as cron, different flavour. A systemd service has almost no environment — no .bashrc, no PATH beyond a minimal default. Use absolute paths, or set Environment= explicitly.

Not testing the calendar expression. systemd-analyze calendar "..." takes one second.

No RandomizedDelaySec on a fleet. Fifty machines starting the same job at exactly 03:00 is a self-inflicted denial of service on whatever they all talk to.

Migrating everything at once. Convert the jobs that matter. Leave the trivial ones in cron. A half-migrated system where the important things are timers is better than a fully-migrated system you rushed.

FAQ

Can cron and timers coexist?

Yes, and most real machines run both. There’s no conflict. Migrate the jobs that need logging, catch-up or dependencies; leave the rest.

How do I see all timers, including ones from packages?

systemctl list-timers --all

You’ll find your distro already ships several — logrotate.timer, fstrim.timer, man-db.timer. Reading them is a good way to learn the idioms.

Can I run a timer as my own user?

Yes, same as services:

mkdir -p ~/.config/systemd/user
systemctl --user enable --now mytimer.timer
sudo loginctl enable-linger $USER     # keep it running after logout

What about anacron?

anacron was the traditional answer to “the machine was off, run it when it comes back.” Persistent=true does the same job, with better logging and without a second scheduler in the mix.

How do I get notified when a job fails?

Add an OnFailure= to the service unit pointing at a notification unit:

[Unit]
OnFailure=notify-failure@%n.service

This is a real advantage over cron, where your options are “parse the mail” or “build it into the script.”

Should I migrate everything?

No. Migrate what matters. The overhead is real and cron is not broken.

Final checklist

  • Service unit uses Type=oneshot
  • No output redirection — let the journal have it
  • Timer has Persistent=true if missed runs matter
  • RandomizedDelaySec= set if more than one machine runs this
  • You enabled the timer, not the service
  • systemd-analyze calendar confirms the schedule
  • systemctl list-timers shows the next run
  • You’ve run it once by hand with systemctl start
  • Absolute paths everywhere; no assumed environment
  • There is some alert for “this did not run”, not just “this failed”