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

风流意气都作罢 提交于 2019-11-29 18:29:49

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.

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

stdin, stdout, stderr = ssh.exec_command('''
command1
&& command2
&& command3
''')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!