Interview Prep/Shell Scripting/cron and systemd timers

How do you alert when a timer-driven service fails?

IntermediateConceptcron and systemd timers
Answer

Use OnFailure= to start a notification unit, passing the failed unit's name with a template:

# backup.service
[Unit]
OnFailure=notify-failure@%n.service

# [email protected]
[Service]
Type=oneshot
ExecStart=/opt/opskit/bin/opskit-alert -s critical -t "unit %i failed" "check: journalctl -u %i"

Also monitor from outside: a "dead man's switch" (the job pings a heartbeat URL on success, and the monitoring system alerts when pings stop) catches the case where the timer was disabled or the host is down.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers