0
点赞
收藏
分享

微信扫一扫

shell脚本监控磁盘空间占用情况

凶猛的小白兔 2022-02-28 阅读 102

 

#!/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

 

举报

相关推荐

0 条评论