磁盘监控报警并发邮件

#!/bin/sh
#auto disk monitor
#by zkg 2019-07-15

echo -e "\033[32m \033[1m"
rm -rf list.txt
LIST=df -h|grep "^/dev/" >> list.txt
cat << EOF

--------------磁盘监控报警----------------

EOF
echo -e "\033[32m \033[0m"
sleep 2

WEEK=date +%u
TIME=date

while read line
do
IP_ADDR=ifconfig eth1|grep "Bcast"|awk '{print $2}'|awk -F: '{print $2}'
D_NAME=echo $line|awk '{print $1,$NF"分区"}'
D_TOTAL=echo $line|awk '{print $2}'
D_AVAIL=echo $line|awk '{print $4}'
D_PERCENT=echo $line|awk '{print $5}'|sed 's/%//g'
if [ "$D_PERCENT" -ge 50 ];then
cat >email.txt <<EOF
*EMAIL*****
通知类型:告警
服务:Disk Monitor
主机:$IP_ADDR
状态:告警
日期/时间:
echo "周$WEEK $TIME"
额外信息:
CRITICAL - DISK MONITOR:$D_NAME Used more than ${D_PERCENT}%
EOF
echo -e "\033[32mthe $D_NAME has been used for more than ${D_PERCENT}%,please check.....\033[0m"
mail -s "$D_NAME warning" [email protected] < email.txt
fi

done <list.txt
echo -e "\033[32m---------------------------------------------\033[0m"
echo "Done."

猜你喜欢

转载自blog.51cto.com/1009516/2425814