#!/bin/bash
#
# 目的:监视系统,如果大于$FS_MAX,则发出警报
FS_MAX=85
FS_LOGFILE=/tmp/fs_logfile
FS_OUTFILE=/tmp/fs_outfile
>$FS_LOGFILE #初试化警报文件
>$FS_OUTFILE #初试化输出文件
usage()
{
printf "\nUSAGE: `basename $0` FS_MAX(85)\n"
}
#将文件系统的结果输出到$FS_OUTFILE
outfile()
{
/bin/df -k | tail -n +2 | grep -v "tmpfs" | "s/\%//g" | gawk '{print $1,$5,$6}' > $FS_OUTFILE
}
#测试,如果大于FS_MAX,则将发送到日志文件
testfile()
{
while read FILESYSTEM FSPERCENT FSMOUNT
do
if [ $FSPERCENT -gt $FS_MAX ]
then
echo "$FILESYSTEM mounted on $FSMOUNT is bigger than $FS_MAX%. Please be careful!" > $FS_LOGFILE
fi
done < $FS_OUTFILE
}
if [ $# -ne 0 -a $# -ne 1 ]
then
usage
exit 1
fi
outfile
testfile
if [ -s $FS_LOGFILE ]
then
cat $FS_LOGFILE
mail < $FS_LOGFILE
fi
exit 0
阅读(1595) | 评论(0) | 转发(0) |