Issue
I have a python program on a RASP PI 2B [Jessie lite] that runs just fine from the terminal command line. However, when trying to run from cron it fails as discussed below. I have set up mta and logging.
from syslog:
Jan 20 15:10:01 carlton CRON[2189]:
(pi) CMD (python amr_water_r9c.py carl1022_104 1541513276 > $HOME/log/logfile 2>&1)
the python program launches two tasks using POPEN with
the first task starts ok
proc1=subprocess.Popen(['rtl_tcp'],shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
the second task
proc2=subprocess.Popen(arg_rtlamr)
results in :
Traceback (most recent call last):
File "amr_water_r9c.py", line 153, in <module>
main()
File "amr_water_r9c.py", line 148, in main
get_data()
File "amr_water_r9c.py", line 99, in get_data
proc2=subprocess.Popen(arg_rtlamr)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
where
arg_rtlamr is defined as :
= ['rtlamr','-format=csv', '-unique=true', \
'-duration=1m',\
'-msgtype='+msgtype,'-filterid='+meter_num , \
' > $HOME/data/elecamr' ]
permissions are:
pi@carlton:~/gopath/bin $ ls -l
-rwxr-xr-x 1 pi pi 4079128 Jan 18 16:42 rtlamr
pi@carlton:~/data $ ls -l
-rw-rw-rw- 1 pi pi 78 Jan 20 14:03 elecamr
pi@carlton:~/log $ ls -l
-rw-rw-rw- 1 pi pi 483 Jan 20 15:10 logfile
Greatly appreciate any clue as to what is going on john
Solution
cron jobs are usually run under a different environment. For example, PATH might not be set to the value as you expected.
Answered By - Shiping