Nagios监控磁盘脚本

#!/bin/bash
#Filename:check_disk.sh
 
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then
 
ROW=`df -h -P|wc -l`
STATUS=0
 
for i in `seq 2 $ROW`
do
        spare=`df -h -P|sed -n "$i"p|awk '{print $4}'`
        use_percentage=`df -h -P|sed -n "$i"p|sed -n "s/\%//"p|awk '{print $5}'`
        spare_percentage=`expr 100 - $use_percentage`
        partition_name=`df -h -P|sed -n "$i"p|awk '{print $6}'`
        if [ "$spare_percentage" -lt "$4" ];then
                echo -n "$partition_name CRITICAL ${spare_percentage}% $spare "
                STATUS[$i]=2
 
        elif [ "$spare_percentage" -lt "$2" ];then
                echo -n "$partition_name WARNING! ${spare_percentage}% $spare "
                STATUS[$i]=1
        else
                echo -n "$partition_name OK ${spare_percentage}% $spare "
                STATUS[$i]=0
        fi
done
STATE=0
for j in `seq 2 $ROW`
do
        if [ "${STATUS[$j]}" -gt "$STATE" ];then
                STATE=${STATUS[$j]}
        fi
done
echo ""
exit $STATE
 
else
        echo "check_disk v1.1"
        echo ""
        echo "Usage:"
        echo "check_disk.sh -w <warnlevel> -c <critlevel>"
        echo ""
        echo "warnlevel and critlevel is percentage value without %"
        echo ""
        echo "Copyright (C) 2015 Nortorm (nortorm@yeah.net)"
        exit
 
 
fi

转载于:https://my.oschina.net/nortorm/blog/424018

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值