[Tutor] SSH with Python
Eric Walstad
eric at ericwalstad.com
Wed Feb 27 23:16:06 CET 2008
Eric Brunson wrote:
> Tom wrote:
>> I have a webfaction server (highly recommended btw) and I'm trying to
>> use automate some tasks over ssh but I'm not having much luck with
>> pyssh http://pyssh.sourceforge.net/ .
>>
>> Some of the docs mention methods that don't exist in the version I
>> downloaded, such as pyssh.run.
>>
>> I'm using windows vista (work pc). Any ideas?
>>
> I've never used pyssh, so I can't comment directly on your problems. We
> use paramiko very successfully. It's well documented and has excellent
> example code included with the source.
>
> http://www.lag.net/paramiko/
Also have a look at pexpect which essentially wraps command line calls.
I use it to automate mysql backups on my webfaction account. Here's
the meat of the code:
import pexpect
cmd = "ssh foouser at foohost 'mysqldump --opt -p foodb > foodb.sql'"
child = pexpect.spawn(cmd)
# expect mysql to prompt for a db password
child.expect('Enter password: ')
# send the password
child.sendline("nottherealpassword")
Homepage:
http://www.noah.org/wiki/Pexpect
It looks like there is now a pexpect SSH module. I've not used it, just
FYI:
http://pexpect.sourceforge.net/pxssh.html
I hope that helps.
Eric.
More information about the Tutor
mailing list