No logging output for cron job

10,680

You've probably been looking at it too long. (Been there, trust me)
The shell script is run_extraction.sh but in the crontab entry, you are missing the ".sh". It should look like:

* * * * * /raid/myuser/database_extraction/run_extraction.sh  >> /raid/myuser/database_extraction/extraction.log

If you want stderr as well stdout logged, you might want it add the redirect on the end (this will help debug things further):

* * * * * /raid/myuser/database_extraction/run_extraction.sh  >> /raid/myuser/database_extraction/extraction.log 2>&1
Share:
10,680
pir
Author by

pir

Updated on September 18, 2022

Comments

  • pir
    pir over 1 year

    I have the cron job below set up through crontab -e. I've tried to go through all the suggestions at Why crontab scripts are not working?, but nothing has helped. The system is clearly running as shown when running sudo grep CRON /var/log/syslog. The file run_extraction.sh has the shebang at the top and execution rights with chmod +x. The log file is being created, but nothing is added to it. More importantly, the python script does not seem to be run as there's no output created from it. The bash script works when run from the command-line.

    I've considered setting up environment variables, but given that even the echo $USER is not producing logging output, something more fundamental seems to be the issue. Any ideas?

    grep output

    Aug  6 15:41:01 scalablegpu3 CRON[13723]: (myuser) CMD (/raid/myuser/database_extraction/run_extraction  >> /raid/myuser/database_extraction/extraction.log)
    Aug  6 15:42:01 scalablegpu3 CRON[13730]: (myuser) CMD (/raid/myuser/database_extraction/run_extraction  >> /raid/myuser/database_extraction/extraction.log)
    

    Crontab entry

    * * * * * /raid/myuser/database_extraction/run_extraction  >> /raid/myuser/database_extraction/extraction.log
    

    Bash file

    #!/bin/bash
    echo $USER
    python database_extraction.py
    
    • Jos
      Jos over 6 years
      You need to include the full path to the .py file.
    • pir
      pir over 6 years
      Ah.. good point!
  • pir
    pir over 6 years
    I initially had the .sh part, but one of the suggestions in the linked thread was to remove extensions.
  • Jeff Burns
    Jeff Burns over 6 years
    Pretty sure its just scripts in the cron.d directories that operate that way, in that they can't have a "." in the filename. Logging stderr will give you the next error to debug. Like is the database_extraction.py script being found in the system path?