Root crontab not executing script

6,871

Solution 1

Check that the cron daemon is running

service crond status
crond (pid  23922) is running...

or

service crond status
crond is stopped

service crond start
Starting crond:                                            [  OK  ]

Solution 2

Make sure your script is executable. Also run your script manually first.

chmod +x scriptname.sh

It is important to not put an extension .sh to your bash script. It causes compatibility problems.

Share:
6,871

Related videos on Youtube

Rhyuk
Author by

Rhyuk

Updated on September 18, 2022

Comments

  • Rhyuk
    Rhyuk almost 2 years

    I have a script listed in my roots crontab

    07 9 * * * /opt/HLRSDATA_2010_OCT/HLRS_Scheduler_sp.sh > /opt/HLRSDATA_2010_OCT/logs/HLRTKJob.log
    

    This script contains the following

    #!/bin/bash
    echo HLRSData Scheduler
    cd /opt/HLRSDATA_2010_OCT
    /usr/bin/java -Xms32m -Xmx1024m -cp ".:HLRSDATA_Premium.jar:lib/commons-net-1.4.1.jar:lib/jakarta-oro-2.0.8.jar:lib/mysql-connector-java-3.1.12-bin.jar:lib/x
    ercesImpl.jar" mx.com.txm.hlrsdata.scheduler.HLRS_Scheduler
    
    /opt/HLRSDATA_2010_OCT/HLRS_Scheduler_Reports_sp.sh
    
    /opt/HLRSDATA_2010_OCT/HLRS_Scheduler_Reports_Redundant_sp.sh
    /opt/HLRSDATA_2010_OCT/HLRS_Delete_Data_sp.sh
    /opt/HLRSDATA_2010_OCT/HLRS_Delete_Data_Redundant_sp.sh
    /opt/HLRSDATA_2010_OCT/HLRS_Delete_Files.sh
    

    The script is not running, I checked in /var/log/cron and theres not even a trace that it at least TRIED to run something.

    Log:

    Oct 18 08:47:19 isvahlrtk01 crontab[46449]: (root) END EDIT (root)
    Oct 18 08:47:22 isvahlrtk01 crontab[46455]: (root) BEGIN EDIT (root)
    Oct 18 08:47:35 isvahlrtk01 crontab[46455]: (root) REPLACE (root)
    Oct 18 08:47:35 isvahlrtk01 crontab[46455]: (root) END EDIT (root)
    Oct 18 08:57:18 isvahlrtk01 crontab[46540]: (root) LIST (root)
    Oct 18 09:00:18 isvahlrtk01 crontab[46548]: (root) LIST (root)
    Oct 18 09:04:24 isvahlrtk01 crontab[46563]: (root) BEGIN EDIT (root)
    Oct 18 09:04:37 isvahlrtk01 crontab[46563]: (root) REPLACE (root)
    Oct 18 09:04:37 isvahlrtk01 crontab[46563]: (root) END EDIT (root)
    Oct 18 09:07:46 isvahlrtk01 crontab[46578]: (root) LIST (root)
    

    Theres a newline at the end of my crontab (edited by crontab -e) and theres no /etc/crontab.allow (and crontab.deny is empty).

    What could be preventing this to be executed?

    Thanks in advance

  • Rhyuk
    Rhyuk over 11 years
    I can run the script manually perfectly with the same account/command mentioned above.
  • Aaron Copley
    Aaron Copley over 11 years
    Source for "compatibility problems" with not using file extensions?
  • Rhyuk
    Rhyuk over 11 years
    /doublefacepalm This was it. Thank you.
  • Valentin Bajrami
    Valentin Bajrami over 11 years
  • Aaron Copley
    Aaron Copley over 11 years
    That wasn't very helpful to your case. It causes no compatibility problem at all. It seems that in rare situations where a script is rewritten, it increases the likelihood of user error. Honestly, it fails to execute once and you say, "Oh yea, I changed the script to use Perl, but not the filename." You change the filename to .pl and move on.
  • Valentin Bajrami
    Valentin Bajrami over 11 years
    I choose to disagree providing these facts. If you are writing for bash in this particular case you don't need to specify an extension. It will just confuse you and assumes you are using #!/bin/sh shebang tag, which subsequently will take away the flexability #!/bin/bash provides.