Re: SSH utility

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edwin.Madari@VerizonWireless.com

    Re: SSH utility

    for similar tasks, I use pexpect http://pypi.python.org/pypi/pexpect.

    spawning bash process and simulate an interactive session. Here sending ls command, retrieving results and exiting. In the spawned process ssh or any other command, is just another command.

    ------------actual session--------------------------
    $ python
    Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
    [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
    Type "help", "copyright" , "credits" or "license" for more information.
    >>import pexpect
    >>c = pexpect.spawn('/bin/bash')
    >>c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    2
    >>c.before, c.after
    ('\x1b[?1034hmadared@N JWARHQD0IT696A: ~\r\n', '$ ')
    >>c.sendline('l s')
    3
    >>c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    2
    >>c.before, c.after
    ('ls\r\x.txt xx.txt xy.txt y.txt\r\nmadare d@NJWARHQD0IT69 6A:~\r\n', '$ ')
    >>c.sendline('e xit')
    5
    >>c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    1
    >>c.before, c.after
    ('exit\r\nexit\ r\n', <class 'pexpect.EOF'>)
    >>exit()
    madared@NJWARHQ D0IT696A:~
    $
    ---------------------------------------------------------------

    hope that helps.

    regards.
    Edwin


    -----Original Message-----
    From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
    [mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
    On Behalf Of James Brady
    Sent: Monday, August 11, 2008 12:26 AM
    To: python-list@python.org
    Subject: SSH utility


    Hi all,
    I'm looking for a python library that lets me execute shell commands
    on remote machines.

    I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
    unfortunately all been unreliable, and repeated questions on their
    respective mailing lists haven't been answered...

    It seems like the sort of commodity task that there should be a pretty
    robust library for. Are there any suggestions for alternative
    libraries or approaches?

    Thanks!
    James
    --




    The information contained in this message and any attachment may be
    proprietary, confidential, and privileged or subject to the work
    product doctrine and thus protected from disclosure. If the reader
    of this message is not the intended recipient, or an employee or
    agent responsible for delivering this message to the intended
    recipient, you are hereby notified that any dissemination,
    distribution or copying of this communication is strictly prohibited.
    If you have received this communication in error, please notify me
    immediately by replying to this message and deleting it and all
    copies and backups thereof. Thank you.


  • Sean DiZazzo

    #2
    Re: SSH utility

    On Aug 11, 5:17 am, Edwin.Mad...@Ve rizonWireless.c om wrote:
    for similar tasks, I use pexpecthttp://pypi.python.org/pypi/pexpect.
    >
    spawning bash process and simulate an interactive session. Here sending ls command, retrieving results and exiting. In the spawned process ssh or any other command, is just another command.
    >
    ------------actual session--------------------------
    $ python
    Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
    [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
    Type "help", "copyright" , "credits" or "license" for more information.>>> import pexpect
    >c = pexpect.spawn('/bin/bash')
    >c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    2
    >c.before, c.after
    >
    ('\x1b[?1034hmadared@N JWARHQD0IT696A: ~\r\n', '$ ')>>c.sendline( 'ls')
    3
    >c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    2
    >c.before, c.after
    >
    ('ls\r\x.txt  xx.txt  xy.txt  y.txt\r\nmadare d@NJWARHQD0IT69 6A:~\r\n', '$ ')>>c.sendline( 'exit')
    5
    >c.expect([pexpect.TIMEOUT , pexpect.EOF, '\$ '])
    1
    >c.before, c.after
    >
    ('exit\r\nexit\ r\n', <class 'pexpect.EOF'>) >>exit()
    >
    madared@NJWARHQ D0IT696A:~
    $
    ---------------------------------------------------------------
    >
    hope that helps.
    >
    regards.
    Edwin
    >
    -----Original Message-----
    From: python-list-bounces+edwin.m adari=verizonwi reless....@pyth on.org
    >
    [mailto:python-list-bounces+edwin.m adari=verizonwi reless....@pyth on.org]
    On Behalf Of James Brady
    Sent: Monday, August 11, 2008 12:26 AM
    To: python-l...@python.org
    Subject: SSH utility
    >
    Hi all,
    I'm looking for a python library that lets me execute shell commands
    on remote machines.
    >
    I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
    unfortunately all been unreliable, and repeated questions on their
    respective mailing lists haven't been answered...
    >
    It seems like the sort of commodity task that there should be a pretty
    robust library for. Are there any suggestions for alternative
    libraries or approaches?
    >
    Thanks!
    James
    --http://mail.python.org/mailman/listinfo/python-list
    >
    The information contained in this message and any attachment may be
    proprietary, confidential, and privileged or subject to the work
    product doctrine and thus protected from disclosure.  If the reader
    of this message is not the intended recipient, or an employee or
    agent responsible for delivering this message to the intended
    recipient, you are hereby notified that any dissemination,
    distribution or copying of this communication is strictly prohibited.
    If you have received this communication in error, please notify me
    immediately by replying to this message and deleting it and all
    copies and backups thereof.  Thank you.
    I second pexpect and the nice little module that comes with it
    ssh_session.py.

    Been using it for ages now!

    ~Sean

    Comment

    Working...