首页 > 解决方案 > 多台服务器的 CPU 利用率报告 - Python

问题描述

我正在尝试以 excel 或 csv 格式获取多台服务器的 ps -aux 命令输出。需要为不同工作表中的服务器打印输出。我无法做到这一点。有人可以通过完成此脚本来帮助我。

import paramiko
import subprocess
import json
import csv

with open(r'filepath\serverlist.json') as f:
data=json.load(f)


client = paramiko.SSHClient()
target_host = txt
un = 'root'
pwd = 'xxx'
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=target_host,username=un,password=pwd)
stdin, stdout, stderr = client.exec_command('ps -aux')

服务器的预期输出如下,并且需要为每个服务器保存在不同的工作表中。

在此处输入图像描述

标签: pythonscripting

解决方案


推荐阅读