Cron Troubleshooting Guide

Identify and fix common cron job issues quickly.

Quick Fix: Most cron issues are caused by permissions, paths, or environment variables. Check these first!

Common Issues

1. Cron Job Not Running

Check cron daemon status:

sudo systemctl status cron # or crond

Verify crontab syntax:

crontab -l

Check system logs:

grep CRON /var/log/syslog journalctl -u cron

2. Permission Issues

Make scripts executable:

chmod +x /path/to/script.sh

⚠️ Always Use Absolute Paths

Cron doesn't know your working directory!

Check file ownership:

ls -la /path/to/script.sh

3. Environment Variables

Problem: Cron runs with minimal environment - no ~/.bashrc, limited PATH

Set PATH in crontab:

PATH=/usr/local/bin:/usr/bin:/bin 0 2 * * * /path/to/script.sh

Source profile if needed:

0 2 * * * source ~/.bashrc && /path/to/script.sh

Best Practices

✅ Prevention Tips

  • Always use absolute paths for commands and files
  • Redirect output for debugging: command >> /var/log/cron.log 2>&1
  • Test commands manually before adding to cron
  • Use proper error handling in scripts
  • Set environment variables explicitly in crontab

Debugging Tips

🔍 Debugging Strategy

  1. Start with simple test commands: * * * * * echo "test" >> /tmp/crontest.log
  2. Remove output redirects temporarily to get email notifications
  3. Check timezone settings if timing seems off
  4. Use our generator tool to validate expressions
  5. Run commands as the same user who owns the crontab

Quick Diagnostics

Run This Diagnostic Script

#!/bin/bash echo "=== Cron Diagnostics ===" echo "Current user: $(whoami)" echo "Current time: $(date)" echo "Cron status:" systemctl status cron | head -3 echo "Crontab entries:" crontab -l echo "Environment in cron:" env | sort

Add this as a temporary cron job to see what environment cron has access to.

Still Having Issues?

Check these specialized troubleshooting guides:

Validate Your Expressions

Use our tools to verify your cron expressions are correct before deploying: