pythonbashcron

Python Not Recognized in Scripts Executed via Cron


Summary

I'm obtaining an error when running a bash script via cron. The script errors out when it reaches the following command; keep in mind that the bash script swaps out ${END_DATE} with the date the script was run:

python -c "import shutil; shutil.make_archive('packages/weekly-report-${END_DATE}', 'zip', 'output/${END_DATE}/')"

Error produced (line 53 is what I posted above):

line 53: python: command not found

Cron settings (python snippet is located in the bash script):

m h dom mon dow   command
5 3 * * 1 /data/run-WP046-cronjob.sh

Shebang for bash script: #!/bin/bash

What I've Tried

I do not get this error when running the script as my profile. Python successfully imports shutil & zips my desired directory. Has anyone experienced this? I've looked online and can't find similar problem examples.

Please let me know if I'm missing needed information for this question.


Solution

  • As John Bollinger pointed out the full path to the executable needed to be specified. I update the script to point to it and error has been corrected. Thank you comment section! Script update below:

    /usr/bin/python -c "import shutil; shutil.make_archive('packages/weekly-report-${END_DATE}', 'zip', 'output/${END_DATE}/')"