前提:
1、多节点之间已经配置好免密登录。ip列表文件已有。
2、每个节点的家目录下已经有systme.sh脚本截取容量
3、python脚本的思路是ssh到每个节点执行脚本拿到数据做判断
4、用 cat -A ip_list.txt 查看每个文件结尾隐藏字符,vim -b 编辑打开ip列表文件。用:%s/vM//g去掉结尾M. 代码里line.strip("\n") 是去掉每一页的换行符。
代码如下:
#!/usr/bin/python
import os,sys,platform
import subprocess
print(platform.python_version)
threshole = 0.75
with open('ip_list.txt','r') as f:
lines = f.readlines()
for line in lines:
command = "sh ~/systme"
ssh_command = "ssh {} {}".format(line.strip("\n"),command)
words = subprocess.check_output(ssh_command,shell=True)
strwords = words.decode("utf-8")
word_list = strwords.split(" ")
for i in word_list[1:]:
num = float(i.replace("%",""))/100
if float(num) > threshole:
print (words)