共计 1077 个字符,预计需要花费 3 分钟才能阅读完成。
脚本检测磁盘使用率,自定义分区,自定义普通告警与严重告警阈值,实现邮箱告警需要先设置Mail_address,填写自己的邮箱即可
#-d|--dir The name of mounted on | |
#-c|--critical A very severe line of cliticel | |
#-w|--warning A number line of warning | |
#-h|--help For help of use information | |
Mail_address= | |
function Usages { | |
echo "`basename $0` [-d|--dir PATH(mounted on name) -c|--critical NUM -w|--warning NUM -h|--help]" | |
} | |
if [ $# -eq 0 ];then | |
Usages | |
exit 1 | |
fi | |
while [ $# -ne 0 ];do | |
case $1 in | |
-h|--help) | |
Usages | |
exit | |
;; | |
-d|--dir) | |
DIR=$2 | |
[ -z $2 ] && echo "Parameter cannot be null....exit....." && exit | |
shift 2 | |
;; | |
-c|--critical) | |
CRITICAL=$2 | |
[ -z $2 ] && echo "Parameter cannot be null....exit....." && exit | |
shift 2 | |
;; | |
-w|--warning) | |
WARNING=$2 | |
[ -z $2 ] && echo "Parameter cannot be null....exit....." && exit | |
shift 2 | |
;; | |
*) | |
Usages | |
exit 2 | |
esac | |
done | |
USEAGE=`df -h|awk -v mount=$DIR '$NF==mount{print $(NF-1)}'|cut -d% -f1` | |
CTMSG="PROBLEM Service Alert:"$DIR" is CRITICAL,Used $USEAGE%" | |
WAMSG="PROBLEM Service Alert:"$DIR" is WARNING,Used $USEAGE%" | |
if [ $USEAGE -ge $CRITICAL ] 2> /dev/null;then | |
echo $CTMSG | mail -s "PROBLEM Service Alert" $Mail_address | |
elif [ $USEAGE -ge $WARNING ];then | |
echo $WAMSG | mail -s "PROBLEM Service Alert" $Mail_address | |
else | |
echo "`date +%F' '%H:%M:%S`-Normal >> /var/log/diskcheck.log" | |
fi |
正文完