≡ Menu

Do You Make These Cron Job Mistakes?

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.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • JAH July 17, 2009, 10:02 am

    You may also want to think about a followup issue on at,atq,atrm, batch.

    Just a thought
    Jay.

  • Ramesh Natarajan July 20, 2009, 12:28 am

    @Jah,

    Thanks for the suggestion. I’ve added that in my list of future articles to write.

  • R&D September 6, 2012, 7:38 am

    THANK YOU

  • Gurpreet June 22, 2014, 8:21 am

    You should also add the issue about using “sudo” in the cron triggered script. Read this: http://unix.stackexchange.com/questions/49077/why-does-cron-silently-fail-to-run-sudo-stuff-in-my-script

  • shufil February 20, 2015, 9:17 am

    Hi,

    i created a bash scrip ,
    if (( $(lsof -i:3007 | wc -l) > 0 ))
    then
    echo “$service is running!!!”
    else
    nohup node test_app.js &
    fi

    this file running with permission 765
    And this scrip is working fine ,but its not working with cron jobs ,added crontab that is

    * * * * * cd /home/samo/Board/App && ./test.sh

    Please advice me , what is issue and how to resolve this

    Shufil