Re: SSH using PEXPECT

Discussion in 'Python' started by Sean DiZazzo, Sep 11, 2008.

  1. Sean DiZazzo

    Sean DiZazzo Guest

    On Sep 10, 6:04 pm, 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.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
     
    Sean DiZazzo, Sep 11, 2008
    #1
    1. Advertising

  2. Sean DiZazzo

    nntpman68 Guest

    Hi,

    wrote:
    > On Sep 10, 7:01 pm, Sean DiZazzo <> wrote:


    > 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\lib\ssh_session.py", line 7, in <module>
    > from pexpect import *
    > File "C:\Python25\lib\site-packages\pexpect.py", line 85, in
    > <module>
    > support it. Pexpect is intended for UNIX-like operating
    > systems.""")
    > ImportError: No module named resource
    >


    You might have cygwin installed,
    but the error mesage sems to indicatem that you don't use cygwin's
    pythonm but the normal windows python,

    You see, that it complains about pexpcet in
    C:\Python25\lib\site-packages\pexpect.py



    just open a cygwin window:

    then cd to the directory containign your script and type
    python new.py.

    you should have at least another error message


    bye

    N
     
    nntpman68, Sep 13, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gil_H
    Replies:
    2
    Views:
    586
    Gil_H
    Apr 4, 2007
  2. crybaby

    pexpect ssh login and ls | grep

    crybaby, Dec 31, 2007, in forum: Python
    Replies:
    6
    Views:
    1,184
    crybaby
    Jan 1, 2008
  3. loial
    Replies:
    0
    Views:
    429
    loial
    Feb 3, 2009
  4. Saqib Ali
    Replies:
    1
    Views:
    372
    Roy Smith
    Dec 26, 2011
  5. Deepika
    Replies:
    2
    Views:
    226
    Deepika
    Nov 14, 2006
Loading...

Share This Page