Step-by-step guide to never miss a silently failing cron again.
Cron tasks are essential but often forgotten. This guide shows you how to monitor them effectively.
In just a few minutes, configure a heartbeat that will alert you if your cron doesn't run.
Crons can fail silently for many reasons:
Follow these steps to configure monitoring:
In MoniTao, create a new heartbeat job with the interval matching your cron. For example, 24 hours for a daily cron.
Add a curl call at the end of your cron command. Use && so the ping is only sent on success.
# Crontab original
0 2 * * * /usr/local/bin/backup.sh
# Crontab avec heartbeat MoniTao
0 2 * * * /usr/local/bin/backup.sh && curl -s -X POST \
https://monitao.com/api/heartbeat/ping/VOTRE_TOKEN \
-H "Authorization: Bearer VOTRE_SECRET"
For better handling, create a wrapper script that signals start, success, or failure:
#!/bin/bash
# backup.sh avec gestion d'erreur
TOKEN="VOTRE_TOKEN"
SECRET="VOTRE_SECRET"
URL="https://monitao.com/api/heartbeat"
# Signal debut
curl -s -X POST "$URL/start/$TOKEN" -H "Authorization: Bearer $SECRET"
# Execution du backup
/usr/bin/mysqldump -u user -p'password' database > /backup/db.sql
RESULT=$?
# Signal succes ou echec
if [ $RESULT -eq 0 ]; then
curl -s -X POST "$URL/ping/$TOKEN" -H "Authorization: Bearer $SECRET"
else
curl -s -X POST "$URL/fail/$TOKEN" -H "Authorization: Bearer $SECRET"
exit 1
fi
Adapt the configuration to your cron:
Increase the grace period to give the cron time to complete.
Yes, create a heartbeat job per server or one if only one should run.
The HTTP ping takes a few milliseconds, completely negligible.
Yes, each ping is recorded with timestamp and duration in the dashboard.
Start free, no credit card required.