Min*_*xer 2 python linux ssh paramiko
我使用Paramiko与某个目标设备建立 SSH 连接,我想执行reboot命令。
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(zip_hostname, username=username, password=password, timeout=1)
try:
stdin, stdout, stderr = ssh.exec_command("/sbin/reboot -f")
# .........
# some code
# .........
except AuthenticationException, e:
print ''
finally:
ssh.close()
Run Code Online (Sandbox Code Playgroud)
但是在执行ssh.exec_command("/sbin/reboot -f")“某些代码”后没有执行,因为程序卡在了exec_command(由于重新启动导致断开连接)。我该怎么做才能解决我的问题?
尝试这个:
ssh.exec_command("/sbin/reboot -f > /dev/null 2>&1 &")
Run Code Online (Sandbox Code Playgroud)
重启的所有输出都被重定向到 /dev/null 以使其不产生任何输出,并且由于最后的“&”符号而在后台启动。希望程序不会以这种方式挂在该行上,因为远程 shell 会返回提示。
| 归档时间: |
|
| 查看次数: |
6967 次 |
| 最近记录: |