[Tutor] Obtaining result from a sendline

Prasad, Ramit ramit.prasad at jpmorgan.com
Wed Oct 31 16:25:15 CET 2012


Dave Wilder wrote:
> Okay, file this under RTFM, but even after research, I cannot figure out the answer to this simple question.
> 
> When I do an ssh in python (version 2.7.3) to a device, I am trying to capture the output of the command.
> However, all I get back is a numerical value.  I am looking to get the actual output from the "ls /var/tmp"
> command below.  This is probably readily available info, but I am just not searching on the python sites
> correctly.
> 
> e.g.
> (Pdb) ssh = sshClient.pxssh()
> (Pdb) ssh.login(server=ip_addr, username=user, password=pswd)
> True
> (Pdb) str = ssh.sendline('ls /var/tmp')
> (Pdb) str
> 12
> (Pdb)

Python does not come with an SSH library, which one are you using?
I am guessing you are using pxssh but it is better for you to 
explicitly let us know any third party module and the operating
system. 

The example they provide on the site[0] says you need to use the 
following to get the output.

""""
s.sendline ('uptime')  # run a command
s.prompt()             # match the prompt
print s.before         # print everything before the prompt.
""""
[0] http://pexpect.sourceforge.net/pxssh.html


Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list