What is a systemd timer and how does it compare to cron?
IntermediateConceptcron and systemd timers
Answer
A timer unit (name.timer) activates a service unit (name.service) on a schedule. Advantages over cron:
- Logs go to the journal:
journalctl -u name.service. systemctl list-timersshows last and next run.Persistent=trueruns missed jobs after downtime (like anacron).RandomizedDelaySec=spreads load across a fleet.- The service never overlaps itself; it is not started again while running.
- Full sandboxing and resource control (
User=,ProtectSystem=,MemoryMax=,CPUQuota=). OnFailure=hooks for alerting, and dependencies (After=network-online.target).
Cron is simpler and universal; timers are the better default on systemd hosts.
More on cron and systemd timers
Explain the five cron time fields with examples.BeginnerWhat is different about the environment a cron job runs in?BeginnerWhat is the difference between a user crontab, `/etc/crontab`, `/etc/cron.d/` and `/etc/cron.daily/`?IntermediateHow do you prevent overlapping cron runs and capture output properly?IntermediateWrite a minimal systemd service and timer that run a backup at 02:30 daily.IntermediateWhat is the difference between `OnCalendar=`, `OnBootSec=` and `OnUnitActiveSec=`?Advanced