在这里,我正在尝试执行 ssh 命令并打印输出。它工作正常,除了 command top
。任何线索如何从顶部收集输出?
import paramiko
from paramiko import SSHClient, AutoAddPolicy, RSAKey
output_cmd_list = ['ls','top']
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname_ip, port, username, password)
for each_command in output_cmd_list:
stdin, stdout, stderr = ssh.exec_command(each_command)
stdout.channel.recv_exit_status()
outlines = stdout.readlines()
resp = ''.join(outlines)
print(resp)