python + linux + cron = problem

Doug Hellmann doughellmann at home.com
Sun Apr 30 14:23:07 CEST 2000


What OS are you on?  I'm not getting any output from that df command
(even if I remove the "grep eggum") under Linux.

After registering the python script directly as a cron job, I had no
problem getting it to run.

The commands module actually runs a different command than what you send
in:

    pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')

Have you tried running that shell command yourself from the command line
to see if you get a better error message?

Doug

Jørn Eilertsen wrote:
> 
> here's the whole script, well the part that gives me grief at least
> :
> #!/usr/bin/python
> import commands
> 
> koblinger = commands.getoutput('df | grep eggum | cut -d 1 -f 1 | cut -d / -f
> 4')
> 
> I've tried to put the shell command into a shell script and run
> commands.getoutput on the script but with the same result. Here's the cron
> entry:
> 0 1 * * *   /usr/local/bin/sjekkmounts
> and I've tried sh /usr/local/bin/sjekkmounts
> 
> Jorn
> 
> Doug Hellmann wrote:
> 
> > Jørn Eilertsen wrote:
> > >
> > > Hi,
> > >
> > > I've posted this earlier but noone replied so I'm trying again
> > >
> > > I have this small program which includes the following line og code:
> > >  mounts = commands.getoutput('df | grep eggum | cut -d 1 -f 1 | cut -d /
> > > -f 4')
> > >
> > > this runs fine from the commandline but when run as a cronjob I get the
> > > following error:
> > >
> > > File "/usr/lib/python1.5/commands.py", line 42, in getoutput
> > >     return getstatusoutput(cmd)[1]
> > >   File "/usr/lib/python1.5/commands.py", line 53, in getstatusoutput
> > >     sts = pipe.close()
> > > IOError: (10, 'No child processes')
> > >
> > > The use of pipes seems to be the trouble here.
> > >
> > > Any help on how the get around this would be greatly appreciated.
> > >
> > >
> >
> > If the problem is really having pipes in the command, why not put your
> > shell commands in a shell script, then run commands.getoutput() on that?
> >
> > If the program runs from the command line but not cron, the problem is
> > more likely to be related to PATH problems within the cron environment.
> > How do you set up the cron job?
> >
> > Doug



More information about the Python-list mailing list