#!/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