Master monitoring of your Linux scheduled tasks
Cron is the historical and most widely used scheduling tool on Linux. For over 40 years, it has enabled automating script execution at defined times. Despite its apparent simplicity, cron hides many pitfalls that can lead to silent failures, going unnoticed for days or even weeks.
Common issues include crontabs cleared during system updates, missing environment variables, relative paths that don't work, and scheduling syntax errors. Without external monitoring, these problems remain invisible because cron itself has no built-in alerting mechanism.
MoniTao offers a heartbeat monitoring solution that perfectly complements Linux cron. By adding a simple curl call at the end of your scripts, you are immediately alerted if a cron doesn't execute or fails, whatever the reason.
Before setting up monitoring, here are the key commands and files for cron management on Linux.
These issues are responsible for the majority of cron failures on Linux. Knowing these pitfalls helps avoid them.
Here are strategies to integrate MoniTao with your existing Linux crons.
Here are several methods to integrate heartbeat monitoring into your Linux crons:
# Method 1: Direct addition in crontab
0 * * * * /path/to/backup.sh && curl -fsS "https://api.monitao.com/ping/TOKEN"
# Method 2: Wrapper script with error handling
#!/bin/bash
set -e
/path/to/backup.sh
curl -fsS --max-time 10 "https://api.monitao.com/ping/TOKEN"
# Method 3: With logging and failure notification
#!/bin/bash
LOG=/var/log/backup.log
if /path/to/backup.sh >> $LOG 2>&1; then
curl -fsS "https://api.monitao.com/ping/TOKEN"
else
curl -fsS "https://api.monitao.com/ping/TOKEN/fail?msg=Backup+failed"
fi
Method 1 is the simplest for existing crons. Method 2 offers better error handling with set -e. Method 3 allows explicitly notifying failures with an error message.
When a cron doesn't work, here are the systematic diagnostic steps.
Configure your MoniTao alerts to be notified of problems without being overwhelmed.
The cron environment is minimal: reduced PATH, no custom shell variables. Use absolute paths (e.g., /usr/bin/php instead of php) and explicitly source your environment files if necessary.
On systemd: journalctl -u cron. On classic systems: /var/log/cron or grep CRON /var/log/syslog. For detailed logs, redirect your script outputs to a dedicated file.
Check that the cron isn't defined in multiple places: user crontab (crontab -l), system file (/etc/crontab), and /etc/cron.d/ directory. Remove duplicates.
Use flock to create a lock: flock -n /tmp/myjob.lock ./myjob.sh. If the lock is already taken, the new instance stops immediately.
Regularly backup your crontabs with crontab -l > /backup/crontab-$(whoami).txt. Automate this backup with... a cron! Also store a copy in your configuration manager.
Execute manually in a cron-like environment: env -i HOME=$HOME /bin/bash -c "your_script.sh". This simulates the minimal environment and reveals PATH or variable issues.
Linux cron remains the most widely used scheduling tool, but its simplicity masks many pitfalls. Silent errors, lost crontabs, and environment issues are frequent causes of undetected failures.
By combining cron configuration best practices with MoniTao heartbeat monitoring, you gain complete visibility into your scheduled task execution. Start with your critical crons and gradually extend coverage.
Start free, no credit card required.