Script error when run as a cronjob.

Linux Centos, When I run a script  manually, it works perfectly but when I run it as a cronjob it throws an error from within the script. My script is a simple launcher for a Python script as follows:

#!/bin/sh
#c21Launcher.sh

cd /
cd /usr/local/bin
Python2.7 /root/amqp_to_db/amqp_to_db.py &
cd /

The error that I get is that "Python2.7 is not recognised as a command!
SimonEngineerAsked:
Who is Participating?
 
Nick UpsonConnect With a Mentor Principal Operations EngineerCommented:
cron runs with a reduced PATH

put the full path to the python2.7 executable in the script
0
 
SimonEngineerAuthor Commented:
am I not doing that with the first two lines of the script?

cd /
cd /usr/local/bin

That is where the Python2.7 file is!
0
 
Nick UpsonPrincipal Operations EngineerCommented:
you assume the current directory is in the PATH,
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
SimonEngineerAuthor Commented:
so should it be:

cd /
/usr/local/bin/Python2.7 /root/amqp_to_db/amqp_to_db.py

?
0
 
Prabhin MPConnect With a Mentor Engineer-TechOPSCommented:
HI ,
replace the script as follows,
/usr/local/bin/python2.7 /root/amqp_to_db/amqp_to_db.py &

hope this will resolve you issue.
if you run manually /python2.7 /root/amqp_to_db/amqp_to_db.py &
 it wil work.
But when you are running from a service ex: cron you need to mention the path of the binary.
0
 
Nick UpsonPrincipal Operations EngineerCommented:
your original one would work with "./python2.7 ...." but better to use use "/usr/local/bin/Python2.7 ...."
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.