我必须在一台远程机器上完成一项工作(使用我的网络服务器),大约需要 10 分钟。
我用过pxssh python 中的模块相同,但它给了我“超时错误”(非阻塞)。
现在,我正在使用 paramiko但是一旦给出指令,它就会返回。
我希望网络服务器等到作业完成。是否有任何 python SSH 模块可用于此。
或者
我们可以通过更改 pxssh
或 paramiko
的任何配置设置来实现相同的目标吗?
最佳答案
您可以使用 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/