Python, subprocess, dump, gzip and Cron

Aidan aweraw at gmail.com
Tue Jun 10 07:21:40 CEST 2008


TT wrote:
> On Jun 10, 2:37 pm, Aidan <awe... at gmail.com> wrote:
>> Hi,
>>
>> I'm having a bit of trouble with a python script I wrote, though I'm not
>> sure if it's related directly to python, or one of the other software
>> packages...
>>
>> The situation is that I'm trying to create a system backup script that
>> creates an image of the system, filters the output though gzip, and then
>> uploads the data (via ftp) to a remote site.
>>
>> The problem is that when I run the script from the command line, it
>> works as I expect it, but when it is run by cron I only get a 20 byte
>> file where the compressed image should be...  does anyone have any idea
>> as to why this might be happening?  Code follows
>>
>> <code>
>>
>> #!/usr/bin/python
>>
>> from subprocess import PIPE, Popen
>> from ftplib import FTP
>>
>> host = 'box'
>>
>> filename = '%s.img.gz' % host
>> ftp_host = '192.168.1.250'
>> ftpuser, ftppass = 'admin', 'admin'
>> dest_dir = '/share/%s' % host
>>
>> dump = Popen('dump 0uaf - /',shell=True,stdout=PIPE)
>> gzip = Popen('gzip',shell=True,stdin=dump.stdout,stdout=PIPE)
>>
>> ftp = FTP(ftp_host)
>> ftp.login(ftpuser,ftppass)
>> ftp.cwd(dest_dir)
>> ftp.storbinary('STOR %s' % filename,gzip.stdout)
>> ftp.quit()
>>
>> print "Image '%s' created" % filename
>>
>> </code>
>>
>> I appreciate all feedback.  Thanks in advance.
> 
> it's possible that the cron doesn't have the environment variables you
> have, especially $PATH. So the script failed to find the command it
> need to create the image.

*fore head slap*

Of course... adding the full path to both those utilities on the Popen 
lines seems to have fixed it.

Thank you very much for your assistance.



More information about the Python-list mailing list