0

I have a python script that will read the temperature of from a probe on the GPIO pins of a Raspberry-Pi, and will append that temperature to a log file. Running the script form terminal with sudo permissions works fine:

sudo python /home/pi/temp.py

I've attempted to run the script every 15 minutes from sudo's crontab file with the line:

*/15 * * * * python /home/pi/temp.py

This fails, with the output being

Traceback (most recent call last):
  File "/home/pi/temp.py", line 8, in <module>
    subprocess.call(['modprobe', 'w1-gpio'])
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I know the issue is with the modprobe subprocess call, but I can't identify what exactly. In my script, I have the following code related to the issue:

import subprocess

subprocess.call(['modprobe', 'w1-gpio'])
subprocess.call(['modprobe', 'w1-therm'])

1 Answer 1

4

This is because cron has its own PATH variable and doesn't use the same path that you do.
For that reason, it would be advisable to call any programs that you use (especially through python's subprocess) with an absolute path to the executable

You could do which modprobe on the commandline to find where modprobe lives (probably in /bin/), and then change your call in subprocess.py to subprocess.call(['/bin/modprobe', 'w1-gpio'])

Sign up to request clarification or add additional context in comments.

1 Comment

This was it. My modprobe lived in /sbin/, but adding this to the subprocess.call in my temp.py script solved my issue. Many thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.