SSH using PEXPECT

Sean DiZazzo half.italian at gmail.com
Thu Sep 11 04:01:34 CEST 2008


On Sep 10, 6:04 pm, yellowblueyel... at gmail.com wrote:
> Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the
> username is 'admin' and password is 'abc123' so far i have the
> following code
>
> import pexpect
> import sys
> import time
> import os
>
> foo = pexpect.spawn('ssh ad... at 10.8.42.38')
> ssh_newKey = 'Are you sure you want to continue connecting'
>
> foo.expect = ssh_newKey
> foo.send = 'yes'
> foo.expect = 'password:'
> foo.send = 'abc123'
>
> --------------------------------------------------------------------------- ----------------------
>
> does this look right?
>
> if not , could someone suggest a way to do this ..
> your help is much appreciated

https://svn.lal.in2p3.fr/projects/CMT/CMTManagement/utils/ssh_session.py

I use a modified version of this.  Simple and effective.

import ssh_session
ssh = ssh_session.ssh_session(user, host, password)
print ssh.ssh("ls -l /tmp")

Thanks Eric and Nigel!

~Sean



More information about the Python-list mailing list