Question: Why my cron job does not get executed at the specified time ?
Answer: There may be lot of reasons why a cron job may not get executed. Let us review 5 important reasons of why a cron job does not run at the specified time and how to resolve those issues.
1. Misinterpretation of Time Field and Specifying Wrong Values.
Misinterpretation of the time field, and given values in the time field which does not mentions the expected/intended time.
For example, to execute a command at 8 PM, you should specify the time in 24 hour format. i.e 8 PM is 20 and not 8 as shown below.
0 8 * * * /home/ubuntu/full-backup [Note: The is wrong for 8 p.m]
0 20 * * * /home/ubuntu/full-backup [Note: This is correct for 8 p.m]
Read our tutorial Linux Crontab: 15 Awesome Cron Job Examples to get a deep understanding on crontab. One of our regular reader Binny has created a web interface which will generate cron entries when you select appropriate values for various crontab fields in the user interface.
2. Invalid Path to Shell Script or Commands in crontab
Make sure the full path to the shell script is specified in the crontab.
0 8 * * * tape-backup [Note: Invalid. No full path specified] 0 8 * * * /home/debian-os/bin/tape-backup [Note: Valid. This is correct with full path]
Note: If you don’t want to give full path in the crontab, make sure to add PATH variable in crontab (example #14)
3. No Execute Permission For the Shell Script in Cron
You might have given the correct command with correct path, but the command might not have execute permission. If you are using any Unix standard commands then it will be having the execute permission set by default.
But, if you are using some user defined commands (shell scripts), make sure to give execute permission to it as shown below.
*/15 * * * * /home/fedora-os/check-disk-space [Note: Executes check-disk-space every 15 minutes] # cd /home/fedora-os # chmod u+x check-disk-space
4. %age in Cron Job Command or Shell Script
If a command has a % in it, your command will not get executed. Refer our previous Crontab %age Issue FAQ to understand how to fix this issue.
5. Disallowed to Execute Cron Job By Sysadmin
A system administrator can decide which user can run cron jobs and which users cannot. So to deny a user from executing a cron job, sysadmin might have placed your username in the /etc/cron.deny file.
If you have root privilege, check the /etc/cron.deny file to make sure your name is not listed in there. If it is listed, edit the file and remove your name. If you don’t have root privilege contact your sysadmin.