Crontab won't start my Python script

I set up a script to run in Crontab on my raspberry pi. When the pi boots the script won't start. If I run the script from the terminal like this:

/var/www/garagestatus2.py

it runs great. I need to run in Crontab as a background.

Any ideas?
dynamicOneAsked:
Who is Participating?
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.

sweetfa2Commented:
Without showing your crontab entry it is hard to know.

Some things to check:
1. When something runs from crontab it does not have the same environment as when you run from your user shell.  Check that there are no environment variables that are required to be set up prior to it running from cron.  You may need another wrapper script.
2. Your path will most likely be different to the one being used by Cron.  Check the paths are fully described in your python script.
3. Is your python environment available from cron.  Do you do some setup in your profile configuration that is not being replicated from cron.
0
dynamicOneAuthor Commented:
Sorry about that, I thought I put my entry in there.

sudo crontab -e

@reboot python /var/www/garagestatus2.py &
0
sweetfa2Commented:
Put the full path to the python command on the crontab line.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Your crontab entry is not complete and you don't need the & btw.

Entry should look like this:
0 8 * * * <full path to>/python /var/www/garagestatus2.py

Open in new window

This would start your .py script every day at 8am. In case your script generates output, you should 'catch' the output like this:
0 8 * * * </full path to>/python /var/www/garagestatus2.py >> </full path to logging folder>/logfile

Open in new window

for example:
0 8 * * * /usr/bin/python /var/www/garagestatus2.py >> /home/someuser/garagestatus2.log

Open in new window

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
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
Python

From novice to tech pro — start learning today.