-1

I'm trying to execute a python script every minute a cron job. I can execute the command using the terminal.

My script can be execute by the following comand:

 python /home/pi/Desktop/sensor_testing/dht11.py

and in sudo crontab -e I typed:

***** python /home/pi/Desktop/sensor_testing/dht11.py

any advice why this isn't working?

Miniex
  • 21
  • 1
  • 3
  • Use an absolute path instead of `python`: `/usr/bin/python` or `/bin/env python` – silel Oct 27 '18 at 16:21
  • I tried this * * * * * /usr/bin/python home/pi/Desktop/sensor_testing/dht11.py but it still doesn't work – Miniex Oct 27 '18 at 16:58
  • My bad then, although you are missing a '/' at the start of "/home/..." but I suppose this is a typo in your copy/paste. Anyway, while looking for an answer, I found [this question](https://serverfault.com/q/449651) and [this answer](https://serverfault.com/a/449652). Hopefully, you'll find something there. =) – silel Oct 27 '18 at 19:39

3 Answers3

0

Take a look here, it's a good explanation about adding a shebang to your python script. it will allow you to run the script easily without calling python explicitly, the only thing you need to do is add a correct python path to the shebang and your set.

tl;dr from link:

for running python 3 script, add this to the top of your script:

#!/usr/bin/env python3

or this for python 2.7

#!/usr/bin/env python2

Avishay Cohen
  • 1,978
  • 2
  • 21
  • 34
0

The time fields are space-separated, i.e.

* * * * * python /home/pi/Desktop/sensor_testing/dht11.py
0

Its should be simply:

Put the absolute python path on the top of your your script First:

#!/usr/local/bin/python   # Just assuming this path

Make the File executable:

chmod +x /home/pi/Desktop/sensor_testing/dht11.py

then place in cron..

***** /home/pi/Desktop/sensor_testing/dht11.py
Karn Kumar
  • 8,518
  • 3
  • 27
  • 53
  • The file is executable and I added the python path to the script but it's still not doing anything... – Miniex Oct 27 '18 at 16:57
  • @Miniex, Does it runs when running through command line? by the way that's script problem not adding to cron. – Karn Kumar Oct 27 '18 at 16:58