SSH utility

Sean DiZazzo half.italian at gmail.com
Mon Aug 11 19:03:20 EDT 2008


On Aug 11, 5:17 am, Edwin.Mad... at VerizonWireless.com 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 at NJWARHQD0IT696A:~\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\nmadared at NJWARHQD0IT696A:~\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 at NJWARHQD0IT696A:~
> $
> ---------------------------------------------------------------
>
> hope that helps.
>
> regards.
> Edwin
>
> -----Original Message-----
> From: python-list-bounces+edwin.madari=verizonwireless.... at python.org
>
> [mailto:python-list-bounces+edwin.madari=verizonwireless.... at python.org]
> On Behalf Of James Brady
> Sent: Monday, August 11, 2008 12:26 AM
> To: python-l... at 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



More information about the Python-list mailing list