Interview Prep/Python for DevOps/Automation scripting & CLI design

A cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?

IntermediateScenarioAutomation scripting & CLI design
Answer

Situation read → Two problems: the failure itself and the lack of observability.

What I'd do →

  1. Make the script exit non-zero on any failure (no catch-all except: pass).
  2. In crontab, call the venv interpreter explicitly and capture output: 0 2 * * * /opt/tool/.venv/bin/python -m tool >> /var/log/tool.log 2>&1.
  3. Add a dead man's switch: on success, ping Healthchecks.io/Cronitor or push last_success_timestamp_seconds to a Pushgateway, and alert when it is stale.
  4. Better: move it to a systemd timer (journal logs, OnFailure= unit) or a Kubernetes CronJob with alerting on failed jobs.

Why → Alerting on absence of success catches every failure mode, including "never started".

Interview tip → "Alert on missing success, not just on errors" shows real on-call experience.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design