Mapperkids Lee
Mapperkids Lee

Reputation: 155

Setup cron job to execute python script inside the bash sh file

I did create a Cron job to run the bash file, it went OK from command line, but if running from the Cron job, it gave me error saying "Python is not a command"

My bash file called: Myscript.sh

#!/bin/bash
cd /var/www/html/public_html/test_scripts
python script1.py serverlog.log 2&>1 &
python script2.py serverlog.log 2&>1 &

My cron job setting

30 5 * * 1-5 root bash Myscript.sh

Anyone know what I'm doing wrong and to get around this problem?

Thanks,

Upvotes: 1

Views: 1965

Answers (1)

Yaroslav Boichuk
Yaroslav Boichuk

Reputation: 1776

You need to put the full path to python. If you don't know path, you can find it with which command:

➜  ~ which python
/usr/bin/python

and then modify your script

#!/bin/bash
cd /var/www/html/public_html/test_scripts
/usr/bin/python script1.py serverlog.log 2&>1 &
/usr/bin/python script2.py serverlog.log 2&>1 &

Upvotes: 1

Related Questions