Interview Prep/Shell Scripting/cron and systemd timers

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-timers shows last and next run.
  • Persistent=true runs 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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers