[ale] Python & pexpect problem

Alex LeDonne aledonne at yahoo.com
Mon Nov 22 17:35:40 EST 2004


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 



More information about the Ale mailing list