Site icon New Generation Enterprise Linux

Catch those silent cron job failures before they bite you

Cron & Task Scheduling (Cron/Systemd Timers/At)

Catch those silent cron job failures before they bite you

đź§© The Challenge

Everyone thinks their cron jobs are running until they notice the database hasn’t been backed up in three weeks. It’s embarrassing to explain to management why the logs were empty while the script was silently choking on a missing path.

đź’ˇ The Fix

Hook your cron jobs into a simple notification pipe so you actually get an alert when things go sideways. You don’t need a heavy monitoring suite, just a way to hear when your scripts scream.

* * * * * /usr/local/bin/my-script.sh >> /var/log/my-script.log 2>&1 || mail -s "Cron job failed: my-script" admin@example.com

⚙️ Why It Works

Adding the double pipe operator ensures the mail command only fires if the preceding script exits with a non-zero status code. It’s a dead-simple way to turn silent failures into actionable inbox noise.

🚀 Pro-Tip: Use flock to wrap your cron jobs so they don’t stomp on each other if a long-running process gets stuck.

Linux Tips & Tricks | © ngelinux.com | 9/21/2026

0 0 votes
Article Rating
Exit mobile version