Crontab @reboot and streamlink PATH issues

153 Views Asked by At

I am attempting to run a python3 script on boot with my raspberry. The python script contains a subprocess call that is giving me problems. I suspect that the problem has to do with the PATH of the streamlink call, but I am not managing to solve it.

the script:

#!/usr/bin/env python3

import subprocess

def streamlistener(streamname):
        try:
                print('Listening to stream: ',streamname)
                grepOut = subprocess.check_output(['streamlink','-p','omxplayer','-a','--timeout 20', '--player-fifo','--retry-strea$
                print(grepOut.decode())
                streamlistener(streamname)
        except subprocess.CalledProcessError as e:
                print("ERRORS: " , e.output.decode())
                streamlistener(streamname)

streamlistener('STREAMNAME')

the crontab (same results without the sleep command):

@reboot sleep 60 && sudo python3 /home/pi/Desktop/stream.py 2>&1 | logger -p user.debug -t 'stream'

The error message I get:

Jun 28 17:40:39 raspberrypi stream: Traceback (most recent call last):
Jun 28 17:40:39 raspberrypi stream:   File "/home/pi/Desktop/stream.py", line 26, in <module>
Jun 28 17:40:39 raspberrypi stream:     streamlistener('northernstreaming')
Jun 28 17:40:39 raspberrypi stream:   File "/home/pi/Desktop/stream.py", line 19, in streamlistener
Jun 28 17:40:39 raspberrypi stream:     grepOut = subprocess.check_output(['streamlink','-p','omxplayer','-a','--timeout 20', '--pla$
Jun 28 17:40:39 raspberrypi stream:   File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
Jun 28 17:40:39 raspberrypi stream:     **kwargs).stdout
Jun 28 17:40:39 raspberrypi stream:   File "/usr/lib/python3.7/subprocess.py", line 472, in run
Jun 28 17:40:39 raspberrypi stream:     with Popen(*popenargs, **kwargs) as process:
Jun 28 17:40:39 raspberrypi stream:   File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
Jun 28 17:40:39 raspberrypi stream:     restore_signals, start_new_session)
Jun 28 17:40:39 raspberrypi stream:   File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
Jun 28 17:40:39 raspberrypi stream:     raise child_exception_type(errno_num, err_msg, err_filename)
Jun 28 17:40:39 raspberrypi stream: FileNotFoundError: [Errno 2] No such file or directory: 'streamlink': 'streamlink'
1

There are 1 best solutions below

0
On

The problem had to do with the PATH pip3 used to install streamlink and not with the subprocess.check_output call, setting the paths properly in both bashrc and at the start of the crontab worked.

Setting path in bashrc:https://linuxize.com/post/how-to-add-directory-to-path-in-linux/

Setting path in cron: https://unix.stackexchange.com/questions/148133/how-to-set-crontab-path-variable