Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91918 > unrolled thread
| Started by | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| First post | 2015-06-02 19:37 -0700 |
| Last post | 2015-06-03 06:07 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Issuing commands using "exec_command()" of paramiko AND also sending commands together Pythonista <kukki.kanchana@gmail.com> - 2015-06-02 19:37 -0700
Re: Issuing commands using "exec_command()" of paramiko AND also sending commands together Sreenathan Nair <sreenath.cg@gmail.com> - 2015-06-03 12:37 +0530
Re: Issuing commands using "exec_command()" of paramiko AND also sending commands together KR <kavithabhaskaran2013@gmail.com> - 2015-06-03 06:07 -0700
| From | Pythonista <kukki.kanchana@gmail.com> |
|---|---|
| Date | 2015-06-02 19:37 -0700 |
| Subject | Issuing commands using "exec_command()" of paramiko AND also sending commands together |
| Message-ID | <3603e97e-686a-47de-aff4-cabfcb930064@googlegroups.com> |
Using paramiko's exec_command(), i would like to send a command, process its output and do it for several other commands. I notice that its not quick enough or something like that. How would I handle that scenario AND also providing multiple commands together (there is 1 post on stackoverflow for issuing multiple commands but I am not sure if someone has tried it. It didnt work for me! Thanks!
[toc] | [next] | [standalone]
| From | Sreenathan Nair <sreenath.cg@gmail.com> |
|---|---|
| Date | 2015-06-03 12:37 +0530 |
| Message-ID | <mailman.92.1433315397.13271.python-list@python.org> |
| In reply to | #91918 |
[Multipart message — attachments visible in raw view] — view raw
Hi,
Could you be more specific about your problem? Perhaps an example of
something similar to what you're trying to do would be helpful.
Usually the process is to instantiate paramiko.SSHCLIENT, use the connect()
method with desired parameters and execute commands using the
exec_command(). If you'd like to process the output of the command
execution, then you would store the result of exec_command() into three
variables (it return a 3-tuple of Channel objects).
i.e com_stdin, com_stdout, com_stderr =
my_ssh_client_instance.exec_command("<command>")
The instance of SSHCLIENT is live until the close() method is called.
Meaning subsequent commands can be executed the same way.
On Wed, Jun 3, 2015 at 8:07 AM, Pythonista <kukki.kanchana@gmail.com> wrote:
> Using paramiko's exec_command(), i would like to send a command, process
> its output and do it for several other commands. I notice that its not
> quick enough or something like that.
>
> How would I handle that scenario AND also providing multiple commands
> together (there is 1 post on stackoverflow for issuing multiple commands
> but I am not sure if someone has tried it. It didnt work for me!
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
[toc] | [prev] | [next] | [standalone]
| From | KR <kavithabhaskaran2013@gmail.com> |
|---|---|
| Date | 2015-06-03 06:07 -0700 |
| Message-ID | <49caa146-b407-4046-813d-05e02d929ef6@googlegroups.com> |
| In reply to | #91923 |
Hi Sreenathan Nair:
import os, sys,
import connectlibs as ssh
s = ssh.connect("xxx.xx.xx.xxx", "Admin", "Admin")
channel = s.invoke_shell()
channel.send("net use F: \\\\xyz.xy.xc.xa\\dir\n")
>>>32
channel.send("net use\n")
>>>7
channel.recv(500)
'Last login: Tue Jun 2 23:52:29 2015 from xxx.xx.xx.xx\r\r\n\x1b]0;~\x07\r\r\n\x1b[32mAdmin@WIN \x1b[33m~\x1b[0m\r\r\n$ net use F: \\\\xyz.xy.xc.xa\\dir\r\nSystem error 67 has occurred.\r\r\n\r\r\nThe network name cannot be found.\r\r\n\r\r\n\x1b]0;~\x07\r\r\n\x1b[32mAdmin@WIN \x1b[33m~\x1b[0m\r\r\n$ net use'
>>>
Above is the what I have for code which is what I am encountering on my setup.
A. I need to be able to parse the o/p of 2 commands 1. "net use F: \\\\xyz.xy.xc.xa\\dir" and 2. "net use".
B. When I use chan.recv(x) -> with certain 'x' bytes. What if I dont know what kind of a response I am expecting - I mean its not a usual response - if I give "x" bytes whereas in reality "x" could be 10000 bytes more than the ACTUAL number of bytes in which case Python hangs.
What do people use in such cases.
On Wednesday, June 3, 2015 at 12:10:08 AM UTC-7, Sreenathan Nair wrote:
> Hi,
>
>
> Could you be more specific about your problem? Perhaps an example of something similar to what you're trying to do would be helpful.
>
>
> Usually the process is to instantiate paramiko.SSHCLIENT, use the connect() method with desired parameters and execute commands using the exec_command(). If you'd like to process the output of the command execution, then you would store the result of exec_command() into three variables (it return a 3-tuple of Channel objects).
>
>
> i.e com_stdin, com_stdout, com_stderr = my_ssh_client_instance.exec_command("<command>")
>
>
> The instance of SSHCLIENT is live until the close() method is called. Meaning subsequent commands can be executed the same way.
>
>
>
>
> On Wed, Jun 3, 2015 at 8:07 AM, Pythonista <kukki.k...@gmail.com> wrote:
> Using paramiko's exec_command(), i would like to send a command, process its output and do it for several other commands. I notice that its not quick enough or something like that.
>
> How would I handle that scenario AND also providing multiple commands together (there is 1 post on stackoverflow for issuing multiple commands but I am not sure if someone has tried it. It didnt work for me!
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web