When deploying software on Linux, it is hard to avoid working with scheduled jobs in crontab. In real environments, I have run into crontab failures many times, so I wrote down the most common causes here for future reference.
- The cron command itself is wrong
This is the most common problem. If you forget to specify the full path to the executable, the job may never run. Another frequent issue is writing a shell script and adding it to crontab without first making it executable.
- The cron service is not running
Crontab jobs depend on the crond service. If all scheduled jobs suddenly stop running, check whether that service is alive first.
- The crontab file format is broken
This is less common, but I have seen it happen. A system integrator once installed a system for us, and later I found that scheduled jobs were not working. After opening the crontab file in vim, I noticed garbled characters. It turned out they had edited the file on Windows and then copied it to Linux. Because of the line-ending difference, the file contained invalid characters and cron ignored it. Fortunately, a simple dos2unix command fixed the problem.
- The crontab file permissions are wrong
Some people like setting everything to 755, but that does not work for every file. I once hit a cron failure where the syntax and file format both looked fine. The clue appeared in /var/log/cron, which showed bad file mode. Someone had changed the crontab file permissions to 755. If the crontab file is executable, cron may reject it. Changing the permissions back to 644 solved the issue.
Finally, here is how I usually troubleshoot crontab problems:
- Add a simple test job at the end of the crontab file, for example:
1 | * * * * * root echo "hello world" >> /root/test_cron |
This writes one line per minute and quickly tells you whether the issue is basic syntax or something else.
- Check the log file. Cron logs are usually written to
/var/log/cron. Looking at the last few lines will often tell you whether cron stopped entirely or whether a job failed during execution.