
Your Cron Jobs Are Failing Silently (Here's a 50-Line Fix)
Last month, my backup cron job failed at 3 AM on a Saturday. I didn't notice until Monday morning when I needed to restore data. Three days of backups — gone. The job had been failing with a disk space error, but cron doesn't care about exit codes by default. It just runs the command and moves on. The Silent Killer Here's what most cron setups look like: # crontab 0 3 * * * /path/to/backup.sh 0 6 * * * /path/to/report.sh 0 * /2 * * * /path/to/cleanup.sh No monitoring. No alerts. No logging. If any of these fail, you won't know until the damage is done. The Fix: Wrap Every Job I built a simple Python wrapper that: Logs start/end time and exit code Sends a Telegram/Slack alert on failure Detects missed runs import subprocess import json from datetime import datetime from pathlib import Path import urllib.request DB = Path . home () / ' .cron-monitor.json ' def load_db (): return json . loads ( DB . read_text ()) if DB . exists () else { ' jobs ' : {}} def save_db ( db ): DB . write_text
Continue reading on Dev.to Python
Opens in a new tab




