0

I have a DSB18B20 temperature sensor and would like to log the readings in a csv file.

I have a script templog.py that stores the readings in a file. The file starts with #!/usr/bin/python That works.

When I run /usr/bin/python /home/pi/mypath/templog.py the script runs as well.

I then tried to add a crontab for that.

sudo chmod -x templog.py 

I was in the correct path for that, therefore no absolute path given.

sudo crontab -e

* * * * * /home/pi/mypath/templog.py

/1 * * * * /home/pi/mypath/templog.py

*/1 * * * * /home/pi/mypath/templog.py

/1 * * * * /usr/bin/python /home/pi/mypath/templog.py

/1 * * * * sudo /usr/bin/python /home/pi/mypath/templog.py

Neither of this works.

  • Who is owner of templog.py ? – ahmetertem Apr 23 '16 at 15:26
  • I guess I am? I created the file but inserted snippets of code I found around the web. – idkfa Apr 23 '16 at 15:43
  • You may check ownership via ls -l – ahmetertem Apr 23 '16 at 15:45
  • The owner is root instead of pi. – idkfa Apr 23 '16 at 15:47
  • 1
    You may change ownership and try again. see askubuntu.com/questions/6723/… – ahmetertem Apr 23 '16 at 16:28
1

Make sure the script is executable.

chmod +x /home/pi/mypath/templog.py

To run every minute the correct crontab entry will then be

* * * * * /home/pi/mypath/templog.py

If you use the root crontab make sure root has permission to write to your log file.

It would probably be best to use your ordinary crontab.

crontab -e rather than sudo crontab -e.

  • I did chmod +x and used 5 stars in crontab as I posted in my question. Is there a reason to use crontab without sudo? I also guess I figured out what the problem was, I'll try and answer the question later. I had a relative path in my script and I think if using crontab I need to use absolute paths. I don't know why that took me 3 hours to figure out though. – idkfa Apr 23 '16 at 15:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.