[ale] Python & pexpect problem
Jay Loden
jloden at toughguy.net
Mon Nov 22 08:59:41 EST 2004
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/)
I'm somewhat stumped since Python is a new thing for me and this is just one
of a few scripts to cut my teeth on. Thanks for the help.
-Jay
The script is below:
#! /usr/bin/env python
import os
import sys
import pexpect
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
def main():
scp("""/html/*.htm""")
scp("""/html/*.jpg""",
""" jay at desktop.jayloden.com:/home/jay/www/jayloden/img/""")
main()
More information about the Ale
mailing list