#使用方法是在crontab中建立如10 */4 * * * /oradata/script/DiskMon.sh 80 >>/dev/null 2>&1
#这样使用空间超过80%就会报警
#!/bin/sh
DSKLOG=/tmp/dsklog.`hostname`;export DSKLOG
TH=$1;export TH
df -hP |column -t |grep -v '/dev/shm' |grep -v Filesystem | awk '{print $5}' | sed s/\%//g | while read percent
do
if [ $percent -gt $TH ]
then
FS=`df -hP |column -t |grep -v '/dev/shm' |grep -v Filesystem | grep $percent | awk '{print $6}'`;export FS
echo "start_time=`date +'%Y/%m/%d %H:%M:%S'`" > $DSKLOG
echo "system_type=UNIX" >> $DSKLOG
echo "node_name=`hostname`" >> $DSKLOG
echo "object_name=DiskSpace" >> $DSKLOG
echo "desc=`hostname` Disk $FS exceed threshold $1 , current capacity is $percent%" >> $DSKLOG
echo "----------------------------------------------" >> $DSKLOG
echo "`df -hP |column -t`" >> $DSKLOG
cat $DSKLOG | /usr/local/bin/mailx -s "SAM20201: `hostname` 10.98.20.123 Disk $FS exceed threshold $1 , current capacity is $percent%" XX@YY.com
fi
done
#这样使用空间超过80%就会报警
#!/bin/sh
DSKLOG=/tmp/dsklog.`hostname`;export DSKLOG
TH=$1;export TH
df -hP |column -t |grep -v '/dev/shm' |grep -v Filesystem | awk '{print $5}' | sed s/\%//g | while read percent
do
if [ $percent -gt $TH ]
then
FS=`df -hP |column -t |grep -v '/dev/shm' |grep -v Filesystem | grep $percent | awk '{print $6}'`;export FS
echo "start_time=`date +'%Y/%m/%d %H:%M:%S'`" > $DSKLOG
echo "system_type=UNIX" >> $DSKLOG
echo "node_name=`hostname`" >> $DSKLOG
echo "object_name=DiskSpace" >> $DSKLOG
echo "desc=`hostname` Disk $FS exceed threshold $1 , current capacity is $percent%" >> $DSKLOG
echo "----------------------------------------------" >> $DSKLOG
echo "`df -hP |column -t`" >> $DSKLOG
cat $DSKLOG | /usr/local/bin/mailx -s "SAM20201: `hostname` 10.98.20.123 Disk $FS exceed threshold $1 , current capacity is $percent%" XX@YY.com
fi
done
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30126024/viewspace-2131729/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30126024/viewspace-2131729/