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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nick UpsonPrincipal Operations EngineerCommented:
cron runs with a reduced PATH

put the full path to the python2.7 executable in the script
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

SimonEngineerAuthor Commented:
so should it be:

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

?
0
Prabhin MPEngineer-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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.