To stop returning through SSH using Pexpect

Posted by chrissygormley on Stack Overflow See other posts from Stack Overflow or by chrissygormley
Published on 2010-04-29T10:50:34Z Indexed on 2010/04/29 10:57 UTC
Read the original article Hit count: 458

Filed under:
|
|

Hello,

I am trying to use pexpect to ssh into a computer but I do not want to return back to the original computer. The code I have is:

#!/usr/bin/python2.6

import pexpect, os

def ssh():

    # Logs into computer through SSH
    ssh_newkey = 'Are you sure you want to continue connecting'
    # my ssh command line
    p=pexpect.spawn('ssh [email protected]')

    i=p.expect([ssh_newkey,'password:',pexpect.EOF])
    p.sendline("password")
    i=p.expect('-bash-3.2')

    print os.getcwd()
ssh()

This allows me to ssh into the computer but when I run the os.getcwd() the pexpect has returned me to the original computer. You see I want to ssh into another computer and use their environment not drag my environment using pexpect. Can anyone suggest how to get this working or an alternative way.

Thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about pexpect