Replacing cron with systemd timers

← Field Notes

Cron is fine. Cron is also where good intentions go to be forgotten: a crontab edited once in 2023, a script that mails its output to a local user nobody reads, and a job that silently stopped working when a path changed.

systemd timers fix the boring parts. Each job is a service plus a timer, so it shows up in the journal with real start and finish times, and systemctl list-timers tells you when it last ran and when it will run next. No more arithmetic with five columns of asterisks.

The pattern I use

One .service file that runs the script, one .timer file with OnCalendar and a RandomizedDelaySec so a fleet of small jobs does not all start on the hour. Add Persistent=true for anything that must catch up after the machine was off — backups, mostly.

What moved, what stayed

Backups, log rotation helpers, and a weekly package update report moved to timers within a month. The one job that stayed on cron is a five-minute health check; timers can do it, but the old entry works and I am not touching it until it gives me a reason.

Rule of thumb after a year of this: if I would want a log of it later, it gets a timer. If it is a one-off, it gets a sticky note.