You added a cron job. It works when you run it manually. But cron just… doesn’t run it. No errors, no output, nothing.
This is one of the most frustrating debugging experiences in Linux. Here’s a systematic checklist to find out what’s actually wrong.
1. Check If Cron Is Running
First, make sure the cron daemon is actually running:
| |
If it’s not running, start it:
| |
2. The PATH Problem (Most Common)
This is the #1 reason cron jobs fail.
When you run a command in your terminal, you have a full PATH with /usr/local/bin, /home/user/.local/bin, etc. Cron has a minimal PATH—usually just /usr/bin:/bin.
Your cron job:
Fails because cron can’t find python3 (it’s in /usr/bin/python3 which should work, but what about pip-installed tools?).
Fix: Use absolute paths for everything:
| |
Or set PATH at the top of your crontab:
| |
Find the absolute path of any command with which:
| |
3. Environment Variables Are Missing
Cron runs with a minimal environment. Your script might depend on:
HOMEUSER- Custom variables like
DATABASE_URLorAPI_KEY - Virtual environment activation
Fix: Source your environment or set variables explicitly:
| |
The wrapper script approach is cleanest:
| |
4. Check the Cron Log
Cron logs vary by distro:
| |
Look for entries like:
If you don’t see your job at all, cron isn’t picking it up.
5. Crontab Syntax Errors
A single syntax error can break your entire crontab. Validate your timing:
Common mistakes:
- Using
*/incorrectly:*/15means “every 15 minutes”, not “at minute 15” - Forgetting that day-of-week 0 and 7 are both Sunday
- Extra spaces or tabs in the wrong places
Use crontab.guru to validate expressions.
6. Permission Problems
Check if your script is executable:
| |
Also verify the cron user can access all paths in the script. If you’re editing root’s crontab but the script tries to write to /home/user/, permissions will fail.
7. Capture Output for Debugging
Cron swallows stdout and stderr by default. Redirect to see what’s happening:
| |
The 2>&1 sends stderr to the same place as stdout—crucial for catching Python tracebacks.
Or email output (if mail is configured):
| |
8. Are You Editing the Right Crontab?
There are multiple places cron jobs can live:
| |
If you’re editing /etc/crontab or files in /etc/cron.d/, remember to include the username:
| |
Quick Debugging Checklist
- ✅ Is cron running? (
systemctl status cron) - ✅ Using absolute paths? (
/usr/bin/python3notpython3) - ✅ Environment variables set?
- ✅ Script is executable? (
chmod +x) - ✅ Logging output? (
>> /path/to/log 2>&1) - ✅ Check cron log for errors? (
grep CRON /var/log/syslog) - ✅ Syntax validated? (crontab.guru)
Nine times out of ten, it’s the PATH. Start there.