#!/bin/bash
#获取IP地址
#这里是测试的
IP=`awk '{print $1}' /etc/hosts | awk 'NR>3 && NR<7'`
for ip in $IP
do
count=2
num=`df -h | wc -l`
while true
do
disk_avail=`ssh root@$ip "df -h" | awk 'NR==i'i=$count | awk '{print $(NF-1)}' | cut -d% -f1`
#过滤出磁盘空间占用率大于5%,
if [[ $disk_avail -ge 5 ]];then
echo "====$ip====
`ssh root@$ip "df -h" | awk 'NR==i'i=$count` " >>/tmp/check_disk.log
fi
(( count++ ))
if [ $count -gt $num ];then
break
fi
done
done
#发送邮件
cat /tmp/check_disk.log | mail -s "Check Host Disk Utilization" *********@qq.com
if [ $? -eq 0 ];then
sed -i '/=/,/\//d' /tmp/check_disk.log
fi