本站将逐步迁移至新站点,点击访问

[SHELL脚本练习]diskcheck.sh

102次阅读
一条评论

脚本检测磁盘使用率,自定义分区,自定义普通告警与严重告警阈值,实现邮箱告警需要先设置Mail_address,填写自己的邮箱即可

#!/bin/bash
#-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
Honest1y
版权声明:本站原创文章,由Honest1y于2017年08月29日发表,共计1480字。
转载提示:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(一条评论)
雪雷 评论达人LV.1
2017-08-31 10:44:59 回复

666,起飞了