I'm using a RaspberryPi with standard Raspbian.
Currently I'm working on some sort of weather station.
For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating mysql datebase with measurement - updateDB.py and the last ( this one is generating problem ) for generating chart out of measurements gathered in database.
I'm a beginner so propably my methods are as dumb as it is possible but this is the reason why I'm asking you for help.
Via command line im running - sudo crontab -e.
My crontab looks like this:
First two scripts are running properly after reboot and every minute.
Unfortunatelly last one imag.py is not running with cron. It is working properly if I simply execute it with python ./imag.py but not with cron.
I'm sure that path for script is ok.
As it is, no, but i am astonished that even the other scripts work. cronjobs are usually started from "init" (process number 0) and the environment of init is usually empty, especially the variable PATH is not set. This means that "python" should not work, only "/some/path/to/python". Find out where the python executable is by calling:
which python
(depending on your shell you might replace "which" with "whence" or "whereis") and put the displayed path in the cron call, like this (analoguously for the other entries):
For the same reasons there could be other environment contents which the script is missing when being called from cron. Enter "set" at the command prompt to display the whole environment of your shell to find out. You will have to set them in the script in this case.
I dont't think that it was the problem cause in python scripts I have #!/usr/bin/python
at start.
Happily I found the bug - in my python script I had a part:
dlugosc_p = open("datebase_length.txt", "r")
read database table length from external file. This file was located in home/pi/meteo so in the same place as imag.py script - but from cron the path for file couldn't be found. I changed this part of python script to -