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

后端 未结 2 1167
野趣味
野趣味 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.

    0 讨论(0)
  • 2020-12-22 09:35

    You need to properly chain the commands together, as in a shell script:

    stdin, stdout, stderr = ssh.exec_command('''
    command1
    && command2
    && command3
    ''')
    
    0 讨论(0)
提交回复
热议问题