Cron Job Not Running , How to Debug It (Beginner-Friendly Guide)
# Step 1 — Check if Cron Service is Running
First, ensure the cron daemon is active.
Debian/Ubuntu:
CentOS/RHEL:
If inactive, start it:
Enable at boot:
## Step 2 — Check the Cron Job Syntax
List cron jobs for the current user:
Common mistakes:
-
Missing newline at the end of the file
-
Wrong time format (
* * * * *) -
Using unsupported characters
Example of correct format:
Explanation:
-
0 2 * * *→ runs at 2:00 AM every day -
>> /home/user/backup.log 2>&1→ logs output and errors
## Step 3 — Check System Cron Logs
Cron logs are usually in:
-
Debian/Ubuntu:
/var/log/syslog -
CentOS/RHEL:
/var/log/cron
Check recent cron activity:
Look for your job’s execution:
-
Was it executed?
-
Did it throw an error?
## Step 4 — Check the PATH Environment Variable
Cron jobs often fail because the environment is minimal. Commands like python3 or mysqldump may not be found.
-
Add full paths to commands:
/usr/bin/python3 -
Or set PATH at the top of crontab:
## Step 5 — Check Permissions
Ensure the script or command is executable:
And the user running cron has permission to access files or directories.
## Step 6 — Redirect Output to Logs
Always log output for debugging:
Check /home/user/script.log after the cron schedule time to see errors.
## Step 7 — Test the Command Manually
Before blaming cron, run your command manually:
If it fails outside cron, cron won’t fix it — fix the script first.
## Step 8 — Check User-Specific vs System Cron Jobs
-
User cron:
crontab -l -
System-wide cron:
/etc/crontabor/etc/cron.d/
Make sure the job is in the correct crontab and has the right syntax.
## Step 9 — Check for SELinux or AppArmor Restrictions
Security modules can prevent cron from executing scripts:
-
Check SELinux (CentOS/RHEL):
-
AppArmor (Ubuntu):
Allow scripts to run by adjusting policies if necessary.
## Step 10 — Beginner-Friendly Checklist
| Problem | Diagnosis | Fix |
|---|---|---|
| Cron daemon not running | systemctl status cron | Start and enable service |
| Syntax errors | crontab -l | Correct time and command format |
| PATH issues | Job fails silently | Use full paths or set PATH in crontab |
| Permission issues | Script not executable | chmod +x and check user access |
| Logs missing | No output | Redirect stdout and stderr to log file |
| Manual command fails | Test command outside cron | Fix script before cron |
| Security restrictions | SELinux/AppArmor | Adjust policies |
## Conclusion
Cron jobs are powerful, but can fail silently due to common issues like:
-
Daemon not running
-
Syntax errors
-
Environment PATH issues
-
Permissions or security restrictions
By following this step-by-step guide, beginners can debug and fix cron jobs confidently, ensuring scheduled tasks run smoothly.