Paramiko session times out, but i need to execute a lot of commands

后端 未结 2 1173
野趣味
野趣味 2020-12-22 09:08

I\'m working on a script (python 2.7) that is wotking with a remote device running Cisco IOS, so I need to execute a lot of commands through ssh. Few commands have no output

2条回答
  •  天命终不由人
    2020-12-22 09:32

    I think what you need is invoke_shell(). For example:

    ssh = paramiko.SSHClient()
    ... ...
    chan = ssh.invoke_shell() # starts an interactive session
    
    chan.send('command 1\r')
    output = chan.recv()
    
    chan.send('command 2\r')
    output = chan.recv()
    ... ...
    

    The Channel has many other methods. You can refer to the document for more details.

提交回复
热议问题