python - python 的 SSH 模块

标签 python ssh timeout nonblocking paramiko

我必须在一台远程机器上完成一项工作(使用我的网络服务器),大约需要 10 分钟。

我用过pxssh python 中的模块相同,但它给了我“超时错误”(非阻塞)。

现在,我正在使用 paramiko但是一旦给出指令,它就会返回。

我希望网络服务器等到作业完成。是否有任何 python SSH 模块可用于此。

或者

我们可以通过更改 pxsshparamiko 的任何配置设置来实现相同的目标吗?

最佳答案

您可以使用 recv_exit_status Channel 上等待命令完成的方法:

recv_exit_status(self) > Return the exit status from the process on the server. This is mostly useful for retrieving the reults of an exec_command. If the command hasn't finished yet, this method will wait until it does, or until the channel is closed. If no exit status is provided by the server, -1 is returned.

例如:

ssh = paramiko.SSHClient()
ssh.connect(remote, username=username, password=password)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("some command")
exit_status = ssh_stdout.channel.recv_exit_status()

关于python - python 的 SSH 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6569833/

相关文章:

用于自动完成文档字符串的 python IDE

ssh - 连接到 ssh 远程主机(在 vpn 网络中)超时

java - 搜索方法返回的超时时间,否则会抛出超时消息

c# - Xunit 超时参数 : minimal working example

python - 如何在python中替换一个对象

Python:将图像从网络保存到磁盘

python - 通过 SOCKS5 代理使用 python 的 easy_install

ubuntu - 为什么 ssh 连接到 gitlab 不起作用(而 http 推送和克隆工作正常)?

linux - shell脚本中sudo over ssh中的多个命令

jQuery 帖子加载