Interview Prep/Shell Scripting/cron and systemd timers

What is the difference between `OnCalendar=`, `OnBootSec=` and `OnUnitActiveSec=`?

AdvancedConceptcron and systemd timers
Answer
  • OnCalendar= is wall-clock time (realtime timer): daily, Mon..Fri 09:00, *-*-01 00:00:00, *:0/15 (every 15 minutes).
  • OnBootSec= is time since boot (monotonic).
  • OnUnitActiveSec= is time since the service was last activated; OnUnitInactiveSec= since it last finished.
[Timer]
OnBootSec=2min
OnUnitActiveSec=5min      # every 5 minutes after the first run

Monotonic timers need a starting point: OnUnitActiveSec= alone never fires if the service has never run, which is why it is paired with OnBootSec= (or OnActiveSec=).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers