Skip to content
cronitorex.com

Monitoring Cron Jobs

Basic pattern

Add two pings around your command — one at start, one at end:

/etc/cron.d/my-app
*/5 * * * * root cronitorex ping my-job run && /opt/my-app/run.sh && cronitorex ping my-job complete || cronitorex ping my-job fail

With exit code tracking

wrapper.sh
#!/bin/bash
cronitorex ping db-backup run
pg_dump mydb | gzip > /backups/db-$(date +%Y%m%d).sql.gz
EXIT=$?
if [ $EXIT -eq 0 ]; then
cronitorex ping db-backup complete --duration $SECONDS
else
cronitorex ping db-backup fail --exit-code $EXIT
fi

Crontab entry

0 3 * * * root /usr/local/bin/wrapper.sh

Duration tracking

Pass --duration in seconds for chart data in the dashboard:

Terminal window
START=$(date +%s)
/usr/local/bin/my-job.sh
DURATION=$(( $(date +%s) - START ))
cronitorex ping my-job complete --duration $DURATION

Silent jobs (no output)

Redirect all output to prevent cron from sending emails:

0 * * * * root /usr/local/bin/wrapper.sh > /dev/null 2>&1