error from Popen only when run from cron

Wildman best_lay at yahoo.com
Sat Jan 27 11:52:23 EST 2018


On Sat, 27 Jan 2018 10:58:36 -0500, Larry Martell wrote:

> I have a script that does this:
> 
> subprocess.Popen(['service', 'some_service', 'status'],
> stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
> 
> When I run it from the command line it works fine. When I run it from
> cron I get:
> 
>     subprocess.Popen(['service', 'some_service', 'status'],
> stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
>   File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
>     errread, errwrite)
>   File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
>     raise child_exception
> OSError: [Errno 2] No such file or directory
> 
> Anyone have any clue as to what file it's complaining about? Or how I
> can debug this further?

Cron provides this as $PATH:  /usr/bin;/usr/sbin

>From within a terminal enter:  whereis service

If service is not in Cron's $PATH, that is your problem.
Adding the complete path to 'service' in the script
should fix things.

If service is in Cron's $PATH, I have no further ideas.

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!



More information about the Python-list mailing list