1

I am using Paramiko to automate few tasks in switch. The Switch OS is not based on unix/linux kind. So I must have to use interactive shell.

Now I am facing issue, without completing first command it is executing second command. I can use time delay between commands but i am thinking it is not right way to automate thing.

Below is the code:

import paramiko
remote_conn_pre = paramiko.SSHClient()
remote_conn_pre.set_missing_host_key_policy(
    paramiko.AutoAddPolicy())
remote_conn_pre.connect(ip, username, password,look_for_keys=False, allow_agent=False)
remote_conn = remote_conn_pre.invoke_shell()
remote_conn.send("\n")
remote_conn.send("ping 10.10.10.10\n")
remote_conn.send("\n")
remote_conn.send("ping 10.10.10.10\n")

Could you Please any one can help me out how to use paramiko that is script has to wait until one command finishes the task and move to next command.

kitty
  • 105
  • 1
  • 3
  • 16
  • Is this of any help maybe? https://stackoverflow.com/questions/34181078/python-paramiko-wait-to-finish-execute-command – errata Jun 01 '17 at 14:16
  • you need to wait for the next shell prompt to show up before sending the next command, just like when you're manually interacting with the shell. – pynexj Jun 01 '17 at 14:33
  • Yes whjm . what you said solution also fine – kitty Jun 01 '17 at 14:42
  • @errata, I just gone through the link before I am posting. It does not see interactive channel establish like this remote_conn = remote_conn_pre.invoke_shell(). But I will give try that link – kitty Jun 01 '17 at 14:46
  • You might have better luck with [pexpect](https://pexpect.readthedocs.io/en/stable/index.html). –  Jun 02 '17 at 14:50

0 Answers0