Monitoring Cron Jobs with Notifery
Stop silent cron job failures from catching you off guard.
Cron jobs fail silently. Your backup script could be broken for weeks before you notice—usually when you actually need that backup.
The fix is simple: wrap your cron commands so they report success or failure. Notifery does this by capturing command output, exit codes, and execution time, then sending you a notification when something goes wrong.
Step-by-Step Setup
1. Create a Notifery Zone
- Sign in to Notifery.
- Create a new Zone (e.g.,
my-server). Zones organize your events logically.
2. Obtain an API Key
- From your Zone settings, generate an API key.
- Copy this key-you’ll need it shortly.
3. Download the Notifery CLI
Use curl to download:
curl -O https://docs.notifery.com/scripts/notifery-event.sh
chmod +x notifery-event.sh
Place this script somewhere accessible, such as /usr/local/bin.
4. Configure the API Key
Edit notifery-event.sh and add your API key:
DEFAULT_API_KEY="your-api-key-here"
5. Testing the Setup
Run a simple test:
./notifery-event.sh "Test Event" my-server "echo 'Hello, Notifery!'"
Check Notifery’s dashboard to confirm receipt.
Monitoring Cron Jobs
Wrap your existing cron jobs with Notifery’s CLI:
Original cron job:
0 2 * * * /usr/bin/mysqldump -u root mydb > /backups/mydb.sql
Wrapped with Notifery:
0 2 * * * /path/to/notifery-event.sh "Daily Backup" my-server#backups "/usr/bin/mysqldump -u root mydb > /backups/mydb.sql" > /dev/null 2>&1
- This sends notifications to Notifery with job output and exit codes.
>/dev/null 2>&1prevents cron email noise; Notifery handles alerting.
Leveraging Exit Codes and Error Alerts
Notifery tracks exit codes automatically:
0: Success- Non-zero: Failure (sends immediate alerts)
Configure your Notifery Zone to notify on errors only, reducing noise.
Advanced Features
Organize Events with Zones and Groups
Use zone#group format to categorize events (e.g., my-server#database). Easily filter and manage alerts.
Structured Logs and Performance Tracking
Notifery captures command output and duration. Structured output (e.g., JSON) is parsed automatically, aiding debugging.
Key Benefits
- Real-time notifications: Instantly detect failures.
- Centralized logs: View cron outputs without accessing servers directly.
- Simple integration: Minimal changes to existing cron jobs.
Conclusion
Once you’ve wrapped your cron jobs with Notifery, you’ll know immediately when something fails instead of discovering it weeks later.