Cron job is not working

6,335

Solution 1

You have to execute it using sh; here is my example

[email protected]
30 11 * * * sh /home/user/backup.sh
30 17 * * * sh /home/user/backup.sh

have a look here cronjob

Solution 2

Fixed this issue. It was a permission issue of calling sh files from cron.

Share:
6,335

Related videos on Youtube

Prajila V P
Author by

Prajila V P

Updated on September 18, 2022

Comments

  • Prajila V P
    Prajila V P over 1 year

    I have a cron job configured at var/spool/cron/testuser, Am calling adindex.sh file from there.

    Am getting results when am directly put the command directly in prompt(php and sh), But cron is not processing this one. I tried to log the cron using tail -f /var/log/cron and got:

    Feb 19 04:05:01 ip-118-139-177-76 CROND[18164]: (inwhosting) CMD (/home/testuser/cronlogs/adindex.sh)
    

    Edit: Output for crontab -l

    MAILTO=""
    */5     *       *       *       *       /home/testuser/cronlogs/adindex.sh
    */5     *       *       *       *       /home/testuser/cronlogs/sendemail.sh
    */5     *       *       *       *       /home/testuser/cronlogs/sendsms.sh
    

    Ouput of cat /home/testuser/cronlogs/adindex.sh

    #wget --user=admin--password=pswd123 http://www.exmaple.com/advertiser/cron/updateindex?cron_key=Inw1234 -O /home/testuser/cronlogs/ad/log_`date "+%Y_%m_%d_%H_%M"`.txt
    
    php /var/www/html/exmaple/cron/advt_index.php
    php /var/www/html/exmaple/cron/ad_index.php
    

    Anybody please tell me what is going wrong?

    • X Tian
      X Tian about 10 years
      There's a typo somewhere in your question is adindex.sh a php script or a shell script. your log shows cron is attempting to execute your command, what does your command look like why do you think it isn't running ?
    • Prajila V P
      Prajila V P about 10 years
      My cron job is to index the solr database, and it is not indexing via cron job. I tried this via command line and works fine
    • S edwards
      S edwards about 10 years
      what is the name of your script ? is it a php script or shell script ?
    • Prajila V P
      Prajila V P about 10 years
      in main cron page i am giving a shell script adindex.sh, which is for executing some php scripts
    • S edwards
      S edwards about 10 years
      can you edit your question to add the result of cron -l
    • Hauke Laging
      Hauke Laging about 10 years
      Is php in cron's $PATH?
    • Angel Todorov
      Angel Todorov about 10 years
      Are you executing the shell script with a php interpreter?
    • Prajila V P
      Prajila V P about 10 years
      Fixed the issue. It was "Permission denied" problem from cron
    • Kusalananda
      Kusalananda about 5 years
      Since the user has "a cron job configured at var/spool/cron/testuser", it makes me believe they manually edited that file rather than using crontab -e. This would explain why some jobs are not running.
  • phemmer
    phemmer about 10 years
    Or chmod a+x /home/user/backup.sh (assuming it has a shebang).