Paramiko Help. Execute command to Interactive Shell which is openedby SSHClient()

S

sagar varule

Hi All,

Im using Paramiko for my SSH automation. Im using method that is shown in demo_simple.py example which comes with Paramiko. Below is code from demo_simple.py.

As you can make out, below code opens SSH connection and opens Interactie Shell, and then wait for the command from user.
I want to submit the command to this Interactive Shell using code.

try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
print '*** Connecting...'
client.connect(hostname, port, username, password)
chan = client.invoke_shell()
print repr(client.get_transport())
print '*** Here we go!'
print
interactive.interactive_shell(chan)
chan.close()
client.close()

Well Another approach I tried is instead of opening interactive_shell, directly issue command using;

stdin, stdout, stderr = client.exec_command(bv_cmd)
for line in stderr.readlines():
print line
for line in stdout.readlines():
print line
But problem here is client.exec_command(bv_cmd) waits for command to execute completely and then it returns to stdout,stderr. And I want to see the ouput from the command during its execution. Because my command takes long time for execution.

Big Picture in My Mind: Big Picture I that want to achieve is, Opening different SSH connection to different host, and it will issue commands to all host, wait for execution. All execution should happen parallel.(just wanted to share my thought, and wanted to hear opinions from you all. Is this possible??). I am not big programmer, just 2 years experience with asp.net C# 2..0 so i would appreciate if discussion happens in simple english.
 
S

sagar varule

Hi All,



Im using Paramiko for my SSH automation. Im using method that is shown indemo_simple.py example which comes with Paramiko. Below is code from demo_simple.py.



As you can make out, below code opens SSH connection and opens InteractieShell, and then wait for the command from user.

I want to submit the command to this Interactive Shell using code.



try:

client = paramiko.SSHClient()

client.load_system_host_keys()

client.set_missing_host_key_policy(paramiko.WarningPolicy())

print '*** Connecting...'

client.connect(hostname, port, username, password)

chan = client.invoke_shell()

print repr(client.get_transport())

print '*** Here we go!'

print

interactive.interactive_shell(chan)

chan.close()

client.close()



Well Another approach I tried is instead of opening interactive_shell, directly issue command using;



stdin, stdout, stderr = client.exec_command(bv_cmd)

for line in stderr.readlines():

print line

for line in stdout.readlines():

print line

But problem here is client.exec_command(bv_cmd) waits for command to execute completely and then it returns to stdout,stderr. And I want to see the ouput from the command during its execution. Because my command takes long time for execution.



Big Picture in My Mind: Big Picture I that want to achieve is, Opening different SSH connection to different host, and it will issue commands to allhost, wait for execution. All execution should happen parallel.(just wanted to share my thought, and wanted to hear opinions from you all. Is this possible??). I am not big programmer, just 2 years experience with asp.net C#2.0 so i would appreciate if discussion happens in simple english.

Can any one comment on this..
 
J

Joshua Landau

Can any one comment on this..

If you don't get replies here it's probably because no-one knows
Paramiko. I suggest posting elsewhere to see if there are any Paramiko
users in other places willing to help. There might be a Paramiko
mailing list.

You also didn't say what didn't work with the first block of code.
Also, what is "interactive"?
 
S

sagar varule

If you don't get replies here it's probably because no-one knows

Paramiko. I suggest posting elsewhere to see if there are any Paramiko

users in other places willing to help. There might be a Paramiko

mailing list.



You also didn't say what didn't work with the first block of code.

Also, what is "interactive"?

Submitting Command to Interactive Shell through code did not work.
 
J

Joshua Landau

Submitting Command to Interactive Shell through code did not work.

In what way didn't it work? What's the problem?

Also, what is "Interactive Shell"?
 
C

Chris Angelico

stdin, stdout, stderr = client.exec_command(bv_cmd)
for line in stderr.readlines():
print line
for line in stdout.readlines():
print line
But problem here is client.exec_command(bv_cmd) waits for command to execute completely and then it returns to stdout,stderr. And I want to see the ouput from the command during its execution. Because my command takes long time for execution.


Are you certain that exec_command is what's waiting, and not readlines()?

ChrisA
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top