SSH using PEXPECT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yellowblueyellow@gmail.com

    SSH using PEXPECT

    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 admin@10.8.42.3 8')
    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

  • Sean DiZazzo

    #2
    Re: SSH using PEXPECT

    On Sep 10, 6:04 pm, yellowblueyel.. .@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...@10.8.42.3 8')
    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


    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

    Comment

    • yellowblueyellow@gmail.com

      #3
      Re: SSH using PEXPECT

      On Sep 10, 7:01 pm, Sean DiZazzo <half.ital...@g mail.comwrote:
      On Sep 10, 6:04 pm, yellowblueyel.. .@gmail.com wrote:
      >
      >
      >
      Hey , I need toSSHinto a server .. (10.8.42.38) usingpexpectthe
      username is 'admin' and password is 'abc123' so far i have the
      following code
      >
      importpexpect
      import sys
      import time
      import os
      >
      foo =pexpect.spawn( 'sshad...@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?
      I am using windows and for reason it wont let me use pexpect even tho
      I have CYGWIN installed


      I get the following error

      Traceback (most recent call last):
      File "new.py", line 1, in <module>
      import ssh_session
      File "C:\Python25\li b\ssh_session.p y", line 7, in <module>
      from pexpect import *
      File "C:\Python25\li b\site-packages\pexpec t.py", line 85, in
      <module>
      support it. Pexpect is intended for UNIX-like operating
      systems.""")
      ImportError: No module named resource


      any ideas?

      Thanks
      A critical module was not found. Probably this operating system does
      not
      support it. Pexpect is intended for UNIX-like operating systems.

      >
      if not , could someone suggest a way to do this ..
      your help is much appreciated
      >

      >
      I use a modified version of this.  Simple and effective.
      >
      import ssh_sessionssh= ssh_session.ssh _session(user, host, password)
      printssh.ssh("l s -l /tmp")
      >
      Thanks Eric and Nigel!
      >
      ~Sean

      Comment

      Working...