Ubuntu cron Basics: Why It's Not Running and How to Fix It
What You'll Learn
- How to check and edit crontab
- What to do when "cron job was set but not running"
- How to investigate cron logs and distinguish typical failure patterns
Quick Summary
When cron isn't working, check these in order:
- Check crontab:
crontab -l - View logs:
grep CRON /var/log/syslog - Verify path: Use absolute paths in crontab
- Check permissions: Executable bit set?
- Test manually: Run the command as root or user
Table of Contents
Prerequisites
- OS: Ubuntu
sudoaccess
1. What is cron?
cron is a daemon that executes scheduled tasks. Combined with crontab, you can automate:
- Periodic log rotation
- Backups
- Sending metrics
- Batch processing
2. How to Check/Edit crontab
2-1. View current user's crontab
$ crontab -l
2-2. Edit crontab
$ crontab -e
2-3. View another user's crontab (requires sudo)
$ sudo crontab -u username -l
2-4. View root's crontab
$ sudo crontab -l
3. Schedule Syntax
* * * * * command │ │ │ │ │ │ │ │ │ └─ Day of week (0-7, 0 and 7 = Sunday) │ │ │ └─── Month (1-12) │ │ └───── Day (1-31) │ └─────── Hour (0-23) └───────── Minute (0-59)
Examples:
0 3 * * *- Every day at 3:00 AM*/5 * * * *- Every 5 minutes0 0 * * 0- Every Sunday at midnight
4. Checking Logs When Not Running
4-1. Check cron logs
$ grep CRON /var/log/syslog | tail -n 50
4-2. Real-time log tracking
$ tail -f /var/log/syslog | grep CRON
4-3. Using journalctl
$ sudo journalctl -u cron -n 100
If logs show "(CRON) CMD..." but nothing happens, the command itself is failing. Run it manually to check.
5. Top 5 Mistakes
Mistake 1: Not using absolute paths
cron runs with minimal environment. Commands like python or node might not be found.
Fix: Use full paths like /usr/bin/python3
Mistake 2: Scripts not executable
$ chmod +x /path/to/script.sh
Mistake 3: Environment variables not set
Variables like PATH, HOME may not be available in cron.
Fix: Define them at the top of crontab or in the script.
Mistake 4: Editing wrong user's crontab
Using crontab -e as user vs sudo crontab -e gives different crontabs.
Mistake 5: Typo in schedule syntax
A space or number in the wrong place can prevent execution entirely.
6. Troubleshooting Steps
Step 1: Verify crontab exists
$ crontab -l $ sudo crontab -l
Step 2: Check cron service
$ sudo systemctl status cron
Step 3: Test command manually
$ /full/path/to/script.sh
Step 4: Add output redirection for debugging
* * * * * /path/to/script.sh >> /tmp/cron.log 2>&1
Summary (Copy-Paste Template)
# Check crontab crontab -l sudo crontab -l # Edit crontab crontab -e # Check cron service sudo systemctl status cron # View logs grep CRON /var/log/syslog | tail -n 50 sudo journalctl -u cron -n 100
Test Environment
Commands in this article were tested on Ubuntu 24.04 LTS / bash 5.2.