ssh到linux服务器没有使用ps命令从python列出PID

问题描述 投票:0回答:1

我试图使用2种方法在linux服务器上执行以下代码,

  1. 手动登录到linux服务器,运行脚本
  2. 从本地(使用ssh命令)

请找到代码:

from subprocess import Popen, PIPE
import os

print os.getpid()

def proc_func():
    proc = Popen(['ps', '-eo', 'pid,lstart', '-a', '-f'], stdout=PIPE, stderr=PIPE)
    for line in proc.stdout:
        print line.strip()

proc_func()

所以,当我手动登录到linux服务器并运行脚本时,它很好,

29706
PID                  STARTED
28811 Wed Oct  3 06:23:51 2018
13474 Wed Oct  3 06:30:24 2018
13484 Wed Oct  3 06:30:29 2018
13485 Wed Oct  3 06:30:29 2018
29706 Wed Oct  3 07:15:19 2018
29708 Wed Oct  3 07:15:19 2018
12030 Wed Oct  3 06:42:11 2018
21910 Wed Oct  3 06:58:40 2018
3445 Fri Jul 20 02:35:07 2018
3444 Fri Jul 20 02:35:07 2018

在这里你可以看到qazxsw poi:qazxsw poi列出

但是当我尝试从本地运行以下命令时

PID

我得到以下输出:

29706

在这里您可以看到qazxsw poi:qazxsw poi未列出

我不确定为什么会这样。

谢谢sirajit

python linux ssh
1个回答
1
投票

你没有用ssh -T <user_id>@<linux_server_address> "python /path/to/the/code/in/linux/server/proc.py" 旗子调用13175 PID STARTED 28811 Wed Oct 3 06:23:51 2018 13474 Wed Oct 3 06:30:24 2018 13484 Wed Oct 3 06:30:29 2018 13485 Wed Oct 3 06:30:29 2018 12030 Wed Oct 3 06:42:11 2018 21910 Wed Oct 3 06:58:40 2018 3445 Fri Jul 20 02:35:07 2018 3444 Fri Jul 20 02:35:07 2018 PID标志需要列出所有进程,甚至是那些不与13175命令调用共享终端或根本没有终端的进程。

© www.soinside.com 2019 - 2024. All rights reserved.