Python, subprocess, dump, gzip and Cron

Aidan aweraw at
Tue Jun 10 06:37:53 CEST 2008


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 

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



from subprocess import PIPE, Popen
from ftplib import FTP

host = 'box'

filename = '%s.img.gz' % host
ftp_host = ''
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.storbinary('STOR %s' % filename,gzip.stdout)

print "Image '%s' created" % filename


I appreciate all feedback.  Thanks in advance.

More information about the Python-list mailing list