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 →
- Make the script exit non-zero on any failure (no catch-all
except: pass). - 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. - Add a dead man's switch: on success, ping Healthchecks.io/Cronitor or push
last_success_timestamp_secondsto a Pushgateway, and alert when it is stale. - 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.
More on Automation scripting & CLI design
Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?BeginnerA colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateYou need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateProduct wants a Slack notification whenever a deploy finishes. You have 30 minutes. What do you build?Beginner