Python 的 SSH 模块

发布于 2024-11-18 03:17:36 字数 412 浏览 10 评论 0原文

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

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

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

我希望网络服务器等待作业完成。有没有可用的 python SSH 模块。

或者

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

I have to do a job (using my web server) on a remote machine that takes about 10 minutes.

I have used pxssh module in python for the same but it gives me "timeout error"(non blocking).

Now, I am using paramiko but that comes back as soon as it gives the instruction.

I want the web server to wait till the job is complete. Is there any python SSH module available for this.

Or

Can we achieve the same by changing any configuration settings of pxssh or paramiko ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-11-25 03:17:36

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

recv_exit_status(自身)
>
返回服务器上进程的退出状态。这对于检索 exec_command 的结果非常有用。如果命令尚未完成,此方法将等待直到完成,或者直到通道关闭。如果服务器没有提供退出状态,则返回-1。

例如:

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()

You can use the recv_exit_status method on the Channel to wait for the command to complete:

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.

For example:

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文