Advertisement
linuxserver Cron jobs are essential for automating tasks on Linux, like backups, scripts, or maintenance. Sometimes, they fail silently, leaving you frustrated.

Cron Job Not Running , How to Debug It (Beginner-Friendly Guide)

5 Min Read Verified Content

# Step 1 — Check if Cron Service is Running


First, ensure the cron daemon is active.

Debian/Ubuntu:

sudo systemctl status cron

CentOS/RHEL:

sudo systemctl status crond

If inactive, start it:

sudo systemctl start cron # Ubuntu/Debian sudo systemctl start crond # CentOS/RHEL

Enable at boot:

sudo systemctl enable cron


## Step 2 — Check the Cron Job Syntax


List cron jobs for the current user:

crontab -l

Common mistakes:

  • Missing newline at the end of the file

  • Wrong time format (* * * * *)

  • Using unsupported characters

Example of correct format:

0 2 * * * /usr/bin/python3 /home/user/backup.py >> /home/user/backup.log 2>&1

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:

sudo grep CRON /var/log/syslog # Debian/Ubuntu sudo tail -n 50 /var/log/cron # CentOS/RHEL

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:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin


## Step 5 — Check Permissions


Ensure the script or command is executable:

chmod +x /home/user/backup.py

And the user running cron has permission to access files or directories.



## Step 6 — Redirect Output to Logs


Always log output for debugging:

* * * * * /home/user/script.sh >> /home/user/script.log 2>&1

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:

/home/user/script.sh

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/crontab or /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):

sestatus
  • AppArmor (Ubuntu):

sudo aa-status

Allow scripts to run by adjusting policies if necessary.



## Step 10 — Beginner-Friendly Checklist


ProblemDiagnosisFix
Cron daemon not runningsystemctl status cronStart and enable service
Syntax errorscrontab -lCorrect time and command format
PATH issuesJob fails silentlyUse full paths or set PATH in crontab
Permission issuesScript not executablechmod +x and check user access
Logs missingNo outputRedirect stdout and stderr to log file
Manual command failsTest command outside cronFix script before cron
Security restrictionsSELinux/AppArmorAdjust 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.

Advertisement
Back to Linuxserver