systemd Timers vs Cron: When to Use Which

Cron has been the standard scheduler on Unix for decades. systemd timers are newer, more powerful, but also more verbose. Cron wins when Cron is perfect for one-line scripts that need to run on a simple schedule. Writing: 0 3 * * * /usr/local/bin/backup.sh is fast, requires no other files, and works on every Unix-like system since the 1970s. systemd timers win when You want any of these: Logging integrated with journalctl Dependencies on other units (After=network-online.target) Resource limits (MemoryMax=, CPUQuota=) Randomized delays to avoid thundering herd (RandomizedDelaySec=) The ability to manually trigger with systemctl start Catch-up behavior after system was off (Persistent=true) Minimal systemd timer example /etc/systemd/system/backup.service: ...

February 17, 2024 · 1 min · Besterry