Migrating from POSIX Cron to systemd Timers on Modern Linux
While classic crontab remains ubiquitous across Unix systems, modern Ubuntu, Debian, and RHEL servers increasingly favor systemd timers for production jobs. systemd timers integrate cleanly with journalctl logging, cgroup resource limits (MemoryMax=, CPUQuota=), network dependency ordering (After=network-online.target), and missed-run catch-up.
Key Differences Between Cron and systemd OnCalendar
- Step Syntax: Cron uses
*/15for every 15 minutes; systemd calendar expressions use a base value with a slash such as00/15for minutes/hours and01/2for days/months. - Range Operator: Cron separates ranges with a hyphen (
1-5orMON-FRI), whereas systemd uses double dots (Mon..Fri). - Verification Built In: Before enabling a timer on a Linux server, always validate the expression directly with
systemd-analyze calendar --iterations=5 "Mon..Fri *-*-* 09:00:00". - Missed Runs (
Persistent=true): If a workstation or on-demand server was powered off during the scheduled time,Persistent=trueruns the missed job immediately on next boot. SetPersistent=falsefor time-sensitive jobs like morning briefings that should not fire unexpectedly hours later.
Frequently Asked Questions
How do I enable and verify a generated systemd timer on Ubuntu/Debian?
Place the two unit files in /etc/systemd/system/, then run sudo systemctl daemon-reload followed by sudo systemctl enable --now my-scheduled-job.timer. Check upcoming triggers with systemctl list-timers --all and inspect logs using journalctl -u my-scheduled-job.service.
What happens if I specify both Day-of-Month and Day-of-Week in Cron?
In standard POSIX/Vixie cron, specifying non-wildcard values in both Day-of-Month (field 3) and Day-of-Week (field 5) creates an OR condition, not an AND condition. For example, 0 9 15 * 1 runs on the 15th of every month AND on every Monday.
Need to audit an entire server crontab at once?
Use the dedicated Crontab Paste Inspector to paste multi-line crontab -l or /etc/cron.d/* files and decode every job in one view.