【问题标题】:How to run two applications (deamon and client) at the same time in single SSH using Python Paramiko如何使用 Python Paramiko 在单个 SSH 中同时运行两个应用程序(守护程序和客户端)
【发布时间】:2022-06-13 13:56:27
【问题描述】:

我想运行同时响应客户端的客户端和守护程序应用程序。

使用 Paramiko 建立到 SSH 的连接。但是我不能同时运行守护进程和客户端。

如何用 Paramiko 做到这一点?

这里的期望是,客户端提供输入为 1,2,3 并且守护程序响应每个输入。 两者都在同一个 SSH 中运行。

谁能帮我解决这个问题?

【问题讨论】:

  • 您是否想过在 2 个单独的线程中拥有 2 个单独的 paramiko 会话?

标签: python ssh paramiko


【解决方案1】:

我假设您可以使用简单的 shell 语法来实现您所需要的。在 Python/Paramiko 中不需要任何花哨的代码。

假设*nix服务器,见How do I run multiple background commands in bash in a single line?

要在 Paramiko 中运行(任何)命令,请参阅 Execute command and wait for it to finish with Python Paramiko

大概是这样的:

stdin, stdout, stderr = ssh_client.exec_command("deamon & client")
stdout.channel.set_combine_stderr(True)
output = stdout.readlines()

如果您需要以某种方式独立运行两个命令(deamon 和 clinet)以获得更好的控制,您可以从这里开始:
Run multiple commands in different SSH servers in parallel using Python Paramiko

除非您不需要打开多个连接(SSHClient)。您只需在同一个 SSHClient 实例上调用两次 SSHClient.exec_command。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    相关资源
    最近更新 更多