LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Paramiko and Python 2.6 (https://www.linuxquestions.org/questions/programming-9/paramiko-and-python-2-6-a-932265/)

ShaqDiesel 03-01-2012 10:32 PM

Paramiko and Python 2.6
 
Hi, I am using paramiko to try and ssh2 into my linux box and run some cli commands(NOT a linux shell). Is this possible, because the following code segment is not working:

Code:

in, out, err = sshObj.exec_command(cmdStr)
for line in out.readlines():
  print line

I am able to connect to the remote host, but the above code prints out the very first line after logging into the Cli instead of the result of the command.

Thanks in advance.

Snark1994 03-03-2012 07:45 AM

What is cmdStr set to, and how are you initialising sshObj? Essentially, can you give us a complete piece of code that runs properly, the output you get when running it, and the output you expect?

EDIT: Wait, are you trying to run a 'sudo' command? In which case the 'Password:' prompt is not the last line of the login, but a request for the sudo password. Just add:
Code:

in.write('password\n')
in.flush()

then the command output should be written to 'out'.


All times are GMT -5. The time now is 08:56 PM.