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.

idkfa
  • 123
  • 6

1 Answers1

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.

joan
  • 71,024
  • 5
  • 73
  • 106
  • 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