I use popen
to execute commands in a Python script, and I call it via cron.
Cron calls out this script but the behavior isn't the same if I call it by hand.
Source:
from subprocess import Popen, PIPE
pp = Popen('/usr/bin/which iptables', shell=True, stdout=PIPE)
data = ''
for ln in pp.stdout:
data = data+ln
if data == '':
print 'ko'
else:
print 'ok : '+data
By hand:
# python /home/user/test.py
> : /sbin/iptables
By cron (in /tmp/err_cron):
* * * * * /usr/bin/python /home/user/test.py >> /tmp/err_cron
ko
ko
ko
Why does cron not run this script normally?