This article covers a few common issues and troubleshooting steps you can take to fix your cron jobs.
Setting an email address
When testing your new cron job, make sure to set an email address for reporting the results. This gives you important information about what may be going wrong if the command line is not running the cron job as desired.
You will only receive an email if the cron fails, or if the cron job itself creates output to view.
Setting the correct file permissions
If you're planning to use external software with a cron job, make sure you have set 'write' and other permissions for the files in your remote folders. If you get an error message about "permission denied" it means your permissions are not set properly. Also specifying the full path of the file you’re writing to can prevent issues with the cron environment running from a different directory.
Using full file paths
The server's crontab needs to know exactly where to read and write files. For example, if you manually run the following file named 'file.sh', it will create a new file named 'output.txt' in the directory you run the command in.
[server]$ sh file.sh > output.txt
However, a cron job would not be able to locate either of these files. Instead, your cron job would need to specify the full paths like this:
0 12 * * * sh /home/username/example.com/file.sh > /home/username/example.com/output.txt
Could not open input file
You may be emailed this when the cron job fails to run. Check the subject of the email that was sent to you. It will start like this:
Make a note of this 'username', then check the Cron Job you created in the panel. These should be the same username. If the username is different than what you see in the panel, make sure to adjust your cron job to the correct username.
Also, make sure the file permissions are set so the user may run it. This usually means 644 permissions for a file and 755 for a directory.
No such file or directory
Check your file paths. Try adding the full file path to the file you're attempting to run as well as the full file path to any file's you're writing to. For example, instead of:
Dedicated server troubleshooting
It's rare that the cron service on a server may stop running. However, if you’re using a Dedicated server, you can verify the cron is running by running this shell command:
[server]$ ps aux | grep cron
You can also check the system log for entries labeled 'CRON' after changing to your admin user and running the following commands.
[server]$ sudo su - [root]# sudo grep CRON /var/log/syslog
If you don’t see any recent CRON entries then you may want to restart the cron service. To restart cron run this command under your Dedicated server's admin user:
[root]# sudo service cron restart