Interview Prep/Shell Scripting/Scenarios: health checks, monitoring and alerts

How do you know a scheduled job actually ran, not just that it did not report failure?

IntermediateScenarioScenarios: health checks, monitoring and alerts
Answer

Situation read → Failure alerts do not fire if the job never starts (timer disabled, host down, cron syntax error).

What I'd do →

  1. Add a dead man's switch: the job pings a heartbeat URL on success (Healthchecks.io, Cronitor, or an internal endpoint), and the monitor alerts when pings stop:
    trap 'curl -fsS -m 10 --retry 3 "$HEARTBEAT_URL/fail" >/dev/null || true' ERR
    ...
    curl -fsS -m 10 --retry 3 "$HEARTBEAT_URL" >/dev/null || true
    
  2. Or check freshness of the job's output: newest backup in S3 younger than 26 hours.
  3. Export a "last success" timestamp metric (node_exporter textfile collector) and alert on time() - last_success > 90000.

Why → Monitoring absence of success catches every failure mode, including ones you did not think of.

Interview tip → Say "alert on missing success, not only on reported failure".

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: health checks, monitoring and alerts