Cron Job Monitoring: Never Miss a Failed Scheduled Task
Learn how to monitor cron jobs effectively. Get alerts when scheduled tasks fail, run late, or don't run at all. Comprehensive guide for Linux cron monitoring.
Wakestack Team
Engineering Team
Who This Is For
This guide is for system administrators and developers who manage cron jobs on Linux servers. If you've ever discovered a critical backup or sync job failed days ago, this guide will help you never miss failures again.
The Problem with Cron Jobs
Silent Failures
Cron jobs fail silently by default:
# This backup might fail and you'd never know
0 2 * * * /scripts/backup.shCommon failure modes:
- Script errors
- Disk full
- Network timeouts
- Permission issues
- Missing dependencies
Delayed Discovery
Without monitoring:
- Day 1: Backup fails
- Day 2-7: More backups fail
- Day 8: Disaster strikes
- Day 8: "Where are the backups?" 😱
No Built-in Monitoring
Linux cron has minimal monitoring:
- MAILTO sends to local mailbox (rarely checked)
- Exit codes aren't tracked
- No central dashboard
- No alerting integration
How Cron Job Monitoring Works
The Heartbeat Pattern
- Create a heartbeat URL for each cron job
- Add a ping to your cron job on success
- Monitor expects ping within schedule
- Missing ping = alert
# Before: Unmonitored
0 2 * * * /scripts/backup.sh
# After: Monitored
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupWhat Gets Detected
| Scenario | Detection |
|---|---|
| Script crashes | No heartbeat → Alert |
| Job never starts | No heartbeat → Alert |
| Job runs late | Late heartbeat → Alert |
| Job takes too long | Duration tracking |
| Job succeeds | Heartbeat received ✓ |
Setting Up Cron Job Monitoring
Step 1: Create Heartbeat Monitor
In Wakestack:
- Add Monitor → Heartbeat type
- Name it (e.g., "Nightly Backup")
- Set schedule:
Expected: Every 24 hours Grace period: 1 hour - Copy the unique URL
Step 2: Update Your Crontab
# Edit crontab
crontab -eAdd heartbeat ping after your job:
# Database backup - runs at 2 AM, pings on success
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup
# Data sync - runs every hour
0 * * * * /scripts/sync.sh && curl -fsS https://ping.wakestack.co.uk/hb/sync
# Weekly report - runs Sunday at midnight
0 0 * * 0 /scripts/report.sh && curl -fsS https://ping.wakestack.co.uk/hb/reportStep 3: Test the Setup
Run your job manually:
/scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupVerify heartbeat received in Wakestack dashboard.
Step 4: Configure Alerts
Set notification channels:
- Email for all failures
- Slack for team visibility
- PagerDuty for critical jobs
Cron Job Monitoring Best Practices
1. Only Ping on Success
Use && to ping only when the job succeeds:
# Good: Only pings if backup succeeds
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup
# Bad: Pings even if backup fails
0 2 * * * /scripts/backup.sh; curl -fsS https://ping.wakestack.co.uk/hb/backup2. Handle Exit Codes Properly
Ensure your scripts exit with proper codes:
#!/bin/bash
set -e # Exit on any error
pg_dump mydb > backup.sql
aws s3 cp backup.sql s3://backups/
# Script exits 0 on success, non-zero on failure3. Set Appropriate Grace Periods
Account for job duration variability:
| Job Duration | Grace Period |
|---|---|
| < 1 minute | 5-10 minutes |
| 1-10 minutes | 15-30 minutes |
| 10-60 minutes | 1-2 hours |
| 1+ hours | 2-3 hours |
4. Add Logging
Log job execution alongside heartbeats:
#!/bin/bash
LOG=/var/log/backup.log
echo "$(date): Starting backup" >> $LOG
if /scripts/backup.sh >> $LOG 2>&1; then
echo "$(date): Backup succeeded" >> $LOG
curl -fsS https://ping.wakestack.co.uk/hb/backup
else
echo "$(date): Backup failed with exit code $?" >> $LOG
exit 1
fi5. Use Unique Heartbeats Per Job
Don't share heartbeat URLs between different jobs:
# Each job gets its own heartbeat
0 2 * * * /scripts/backup-db.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup-db
0 3 * * * /scripts/backup-files.sh && curl -fsS https://ping.wakestack.co.uk/hb/backup-files
0 * * * * /scripts/sync-data.sh && curl -fsS https://ping.wakestack.co.uk/hb/sync-dataCommon Cron Job Patterns
Pattern 1: Simple Job
# Job runs, ping on success
0 2 * * * /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupPattern 2: With Timeout
# Timeout after 30 minutes
0 2 * * * timeout 1800 /scripts/backup.sh && curl -fsS https://ping.wakestack.co.uk/hb/backupPattern 3: With Locking
# Prevent overlapping runs
0 * * * * flock -n /tmp/sync.lock /scripts/sync.sh && curl -fsS https://ping.wakestack.co.uk/hb/syncPattern 4: With Retry Logic
#!/bin/bash
# retry-backup.sh
for i in 1 2 3; do
if /scripts/backup.sh; then
curl -fsS https://ping.wakestack.co.uk/hb/backup
exit 0
fi
sleep 300 # Wait 5 min before retry
done
exit 1 # All retries failed, no heartbeat sentPattern 5: Duration Tracking
#!/bin/bash
START=$(date +%s)
/scripts/backup.sh
EXIT_CODE=$?
END=$(date +%s)
DURATION=$((END-START))
if [ $EXIT_CODE -eq 0 ]; then
curl -fsS "https://ping.wakestack.co.uk/hb/backup?duration=${DURATION}"
fi
exit $EXIT_CODETroubleshooting Cron Job Monitoring
Heartbeat Not Received
Check 1: Is the job running?
# Check cron logs
grep CRON /var/log/syslog | tail -20Check 2: Is the job succeeding?
# Run manually
/scripts/backup.sh
echo "Exit code: $?"Check 3: Can the server reach the heartbeat URL?
curl -v https://ping.wakestack.co.uk/hb/testCheck 4: Is curl installed?
which curl
# Or use wget instead
wget -q -O /dev/null https://ping.wakestack.co.uk/hb/backupJob Runs But Heartbeat Fails
Add debugging:
0 2 * * * /scripts/backup.sh && curl -fsS -w "\\n%{http_code}\\n" https://ping.wakestack.co.uk/hb/backup >> /var/log/heartbeat.log 2>&1Too Many False Alerts
- Increase grace period
- Check for network reliability issues
- Add retry logic to curl:
curl -fsS --retry 3 --retry-delay 5 https://ping.wakestack.co.uk/hb/backupCron Job Monitoring Checklist
Before going live:
- Heartbeat URL created for each job
- Schedule matches cron schedule
- Grace period accounts for duration
- Ping only on success (
&¬) - Alert channels configured
- Test run completed successfully
- Alerts tested manually
Wakestack Cron Job Monitoring
Monitor your scheduled tasks with heartbeat monitoring.
Features:
- Unique URLs per job
- Configurable schedules
- Grace periods
- Duration tracking
- Multi-channel alerts
- Dashboard visibility
Pricing:
- Free: 5 monitors (heartbeats count)
- Pro: 50 monitors, $29/mo
- Enterprise: Unlimited, $99/mo
Related Resources
Frequently Asked Questions
How do I monitor cron jobs?
Use heartbeat monitoring: add a curl command to your cron job that pings a unique URL when the job completes. If the ping doesn't arrive on schedule, you get alerted.
Why do cron jobs fail silently?
Cron jobs fail silently because there's no built-in notification system. By default, cron only sends email (often to a local mailbox nobody checks). External monitoring catches these failures.
Can I monitor cron jobs for free?
Yes, Wakestack's free tier includes heartbeat monitoring for cron jobs. You get 5 monitors which can include cron job heartbeats.
Related Articles
Heartbeat Monitoring: Track Background Jobs and Scheduled Tasks
Learn how heartbeat monitoring works for cron jobs, background workers, and scheduled tasks. Get alerts when jobs fail to run or take too long.
Read moreServer Monitoring: Complete Guide to Infrastructure Visibility
Learn how to monitor your servers effectively - CPU, memory, disk, and processes. Understand why server monitoring matters and how it complements uptime monitoring.
Read moreUptime Monitoring: The Complete Guide for 2026
Learn everything about uptime monitoring - what it is, why it matters, how to set it up, and which tools to use. A comprehensive guide for DevOps teams and developers.
Read moreReady to monitor your uptime?
Start monitoring your websites, APIs, and services in minutes. Free forever for small projects.