0

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
  • 1
    You need to include the full path to the .py file. – Jos Aug 6 '17 at 20:41
  • Ah.. good point! – pir Aug 6 '17 at 20:41
2

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
  • I initially had the .sh part, but one of the suggestions in the linked thread was to remove extensions. – pir Aug 6 '17 at 19:57
  • 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? – Jeff Burns Aug 6 '17 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.