I have a script
/home/projects/temperature_logger/analyze.py that does some work on a
temp.log file, which is really a csv of a date and the current raspberry pi temperature. This python script also logs the results to a
.log file. Calling it from the command line like
sudo python3 analyze.py works as expected, but for some reason I cannot get it ot work with crontab.
I have run
sudo chmod +x analyze.py as well as
sudo chmod ugo+w analyze.py.
whereis python3 says
/usr/bin/python3. The shebang at the top of my
analyze.py script is
My crontab script is
* * * * * /usr/bin/python3 /home/projects/temperature_logger/analyze.py
For testing purposes all I have actually running right now is
if __name__ == '__main__':
in my analyze.py but I do not see this getting populated to my log file unless I manually call
sudo python3 analyze.py from within the directory.
Update: I added all permissions for my user
sudo chmod -R a+rwx /home/projects/temperature_logger. I then changed the crontab, cleared out my root cron and put the call to the python script under ubuntu's cron file. I do see this reflected under the syslog now
It does not seem to indicate any error. However, the script which when I call it with
python3 analyze.py it does write properly to my
scripts.log file, but when it's called from the cron, which it says is running the syslog - I don't see anything logged.
So this was due to me misunderstanding waht the home directory for my user account was and what the current working directory of the script was. In my
analyze.py script I had
logging.basicConfig(filename='scripts.log', ...), which when I ran from the directory with
sudo, wrote to
/home/projects/temperature_logger/scripts.log, but when it was called from my user's cron file, it wrote to