[ale] Python & pexpect problem

Jay Loden jloden at toughguy.net
Mon Nov 22 18:34:59 EST 2004


Ok, maybe I can import glob module and use that instead of building the list 
up for the command. 

-Jay

On Monday 22 November 2004 05:34 pm, Alex LeDonne wrote:
> Jay-
>
> I suspect the problem is that the command you give to spawn() doesn't
> go through a shell, so the * file glob doesn't work - it's just a
> literal splat character.
>
> I think for the "else" case, you'll to build the list of the files in
> python, so the command you spawn ends up looking like
>
> scp file1.htm file2.htm file3.htm ... scp_to
>
>
> -Alex
>
> > From: Jay Loden <jloden at toughguy.net>
> > Subject: [ale] Python & pexpect problem
> > To: Atlanta Linux Enthusiasts <ale at ale.org>
> >
> > I have a script that I'm trying to use to do a backup of my website
> > to my home machine using scp.  It uses pexpect to enter the password
> > for scp, and it's supposed to get all the .htm and .jpg files from
> > /var/www/html/ and download them to my desktop machine.
> >
> > However, when I run the script, all I get is an error saying
> > "/var/www/html/*.htm" : file does not exist
> >
> > Oddly, if I run the command the usual way from a prompt, it works
> > fine (i.e. scp /var/www/html/*.htm
> > jay at desktop.jayloden.com:/home/jay/)
>
> [snipped all but the relevant function]
>
> > def scp(path, scp_to = """
> > jay at desktop.jayloden.com:/home/jay/www/jayloden/html/"""):
> > 	'''does the actual scp work'''
> > 	password = "password"
> > 	command = "scp " + path + scp_to
> > 	recurse_cmd = "scp -r " + path + scp_to
> >
> > 	if os.path.isdir(path):
> > 		child = pexpect.spawn(recurse_cmd)
> > 		child.expect('password:')
> > 		child.sendline(password)
> > 		child.expect(pexpect.EOF)
> >
> > 		print child.before
> >
> > 	else:
> > 		child = pexpect.spawn(command)
> > 		child.expect('password:')
> > 		child.sendline(password)
> > 		child.expect(pexpect.EOF)
> >
> > 		print child.before
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list