Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52172 > unrolled thread
| Started by | sagar varule <sagar.varule@gmail.com> |
|---|---|
| First post | 2013-08-08 00:20 -0700 |
| Last post | 2013-08-11 11:10 +0100 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.python
Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() sagar varule <sagar.varule@gmail.com> - 2013-08-08 00:20 -0700
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() sagar varule <sagar.varule@gmail.com> - 2013-08-10 22:18 -0700
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() Joshua Landau <joshua@landau.ws> - 2013-08-11 06:58 +0100
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() sagar varule <sagar.varule@gmail.com> - 2013-08-11 00:02 -0700
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() Joshua Landau <joshua@landau.ws> - 2013-08-11 08:10 +0100
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() Chris Angelico <rosuav@gmail.com> - 2013-08-11 09:57 +0100
Re: Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() Joshua Landau <joshua@landau.ws> - 2013-08-11 11:10 +0100
| From | sagar varule <sagar.varule@gmail.com> |
|---|---|
| Date | 2013-08-08 00:20 -0700 |
| Subject | Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient() |
| Message-ID | <c665ba05-2843-4e44-a6d0-b29d508fd9f4@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | sagar varule <sagar.varule@gmail.com> |
|---|---|
| Date | 2013-08-10 22:18 -0700 |
| Message-ID | <3e9da33f-f37f-4df2-9c97-c4f2010f0471@googlegroups.com> |
| In reply to | #52172 |
On Thursday, August 8, 2013 12:50:25 PM UTC+5:30, sagar varule wrote: > 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. Can any one comment on this..
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-08-11 06:58 +0100 |
| Message-ID | <mailman.467.1376200760.1251.python-list@python.org> |
| In reply to | #52360 |
On 11 August 2013 06:18, sagar varule <sagar.varule@gmail.com> wrote: > 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"?
[toc] | [prev] | [next] | [standalone]
| From | sagar varule <sagar.varule@gmail.com> |
|---|---|
| Date | 2013-08-11 00:02 -0700 |
| Message-ID | <65f9e894-2528-46da-875f-2bebfaa182c1@googlegroups.com> |
| In reply to | #52361 |
On Sunday, August 11, 2013 11:28:31 AM UTC+5:30, Joshua Landau wrote: > On 11 August 2013 06:18, sagar varule <sagar.varule@gmail.com> wrote: > > > 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"? Submitting Command to Interactive Shell through code did not work.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-08-11 08:10 +0100 |
| Message-ID | <mailman.469.1376205088.1251.python-list@python.org> |
| In reply to | #52363 |
On 11 August 2013 08:02, sagar varule <sagar.varule@gmail.com> wrote: > On Sunday, August 11, 2013 11:28:31 AM UTC+5:30, Joshua Landau wrote: >> You also didn't say what didn't work with the first block of code. > > 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"?
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-08-11 09:57 +0100 |
| Message-ID | <mailman.470.1376211443.1251.python-list@python.org> |
| In reply to | #52172 |
On Thu, Aug 8, 2013 at 8:20 AM, sagar varule <sagar.varule@gmail.com> wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-08-11 11:10 +0100 |
| Message-ID | <mailman.476.1376215889.1251.python-list@python.org> |
| In reply to | #52172 |
On 11 August 2013 09:57, Chris Angelico <rosuav@gmail.com> wrote: > On Thu, Aug 8, 2013 at 8:20 AM, sagar varule <sagar.varule@gmail.com> wrote: >> 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()? That's a very good catch; Sagar, you might want to look at: http://stackoverflow.com/a/4896288/1763356 for a good solution if this is the case. There might be more builtin ways (maybe select.select) but I'm betting that link's the most rigorous.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web