Persistent ssh session to Cisco router

前端 未结 4 1325
[愿得一人]
[愿得一人] 2020-12-31 19:05

I have search on this site and multiple other locations but I have been unable to resolve my problem of connecting and maintaining ssh session after one command. Below is my

4条回答
  •  不知归路
    2020-12-31 19:30

    The above program does not work when I need to configuration mode because ssh session is not reused

    Your ssh session will be reused once you move the connect and close outside of the loop, but each exec_command() happens in a new shell (through a new channel), and are unrelated. You will need to format your commands so that they don't require any state from the shell.

    If I remember correctly, some Cisco devices only allow a single exec, and then close the connection. In that case, you will need to use invoke_shell(), and work interactively using the pexpect module (which you already have imported, but aren't using).

提交回复
热议问题