Site icon New Generation Enterprise Linux

Catch cron failures before they turn into late-night pages

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

Catch cron failures before they turn into late-night pages

đź§© The Challenge

Setting up a cron job feels great until you realize it’s been silently failing for three days because the directory moved or a token expired. I’ve wasted so many hours digging through logs just to see why a script that worked on Tuesday decided to vanish into the void on Friday.

đź’ˇ The Fix

Hook your cron jobs up to a simple health check or error handler so you get an email the second something goes sideways. You don’t need a fancy monitoring suite, just a basic shell redirect that triggers only when things break.

0 * * * * /usr/local/bin/backup-db.sh || mail -s "Backup Failed: $(hostname)" admin@example.com

⚙️ Why It Works

Using the double pipe operator tells the shell to run the second command only if the first one exits with a non-zero status. It is the easiest way to turn a silent error into an immediate alert.

🚀 Pro-Tip: If you’re managing a ton of these, look into setting up a dedicated healthcheck URL instead of flooding your inbox.

Linux Tips & Tricks | © ngelinux.com | 11/27/2026

0 0 votes
Article Rating
Exit mobile version