Interview Prep/Shell Scripting/Troubleshooting: cron and systemd timers

A timer with only `OnUnitActiveSec=10min` was enabled and started, but `systemctl list-timers` shows `NEXT: -` and the job has never run.

AdvancedTroubleshootingTroubleshooting: cron and systemd timers
Answer

Likely causes → OnUnitActiveSec= is relative to the last time the service was activated. If the service has never run since boot, there is no reference point, so the timer never elapses. It only "works" on hosts where someone started the service manually once.

Diagnose →

systemctl list-timers --all opskit-health.timer
systemctl show opskit-health.service -p ActiveEnterTimestamp     # empty: never activated

Fix → Add a trigger that does not depend on prior runs:

[Timer]
OnBootSec=2min
OnUnitActiveSec=10min
AccuracySec=30s

Or use a calendar schedule: OnCalendar=*:0/10.

Prevent → Pair every monotonic OnUnitActiveSec= with OnBootSec= or OnActiveSec=, and verify a fresh host (or a reboot) actually runs the job.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: cron and systemd timers