#!/bin/bash
partion_list=( 'df -h | awk ‘NF>3&&NR>1{sub(/%/,””,$(NF-1))print $NF,$(NF-1)}’' )
critical=90
notification_email()
{
emailuser='user@qq.com' “发送邮件地址”
emailpasswd='password'“成功开启POP3/SMTP服务,在第三方客户端登录时,密码框请输入的授权码”
emailsmtp='smtp.qq.com'
sendto='user2@qq.com' “接收邮箱地址”
title='Disk Space Alarm' “邮件标题”
/usr/local/bin/sendEmail -f $emailuser -t $sendto -s $emailsmtp -u $title -xu $emailuser -xp $emailpasswd -m $emailmessage
}
crit_info=””
for (( i=0i<${#partition_list[@]}i+=2 ))
do
if [ “${partition_list[ ((i+1)) ]}” -lt “$critical” ]then
echo “ok! ${partition_list[i]} used ${partition_list[ ((i+1)) ]}%”
else
if [ “${partition_list[ ((i+1)) ]}” -gt “$critical” ]then
crit_info=$crit_info”Warning!!! ${partition_list[i]}
used ${partition_list[ ((i+1) ] }%\n”
fi
fi
done
if [ “$crit_info” != ”” ]then
echo -e $crit_info | notification_email
fi
上面脚本的功能是监控每个磁盘分区,当磁盘分区使用空间超过90%时,就通过sendEmail来发送邮件告警。sendEmail是个开源工具,可以从http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz下载;
解压后把sendEmail拷贝到/usr/local/bin下即可。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)