监视文件系统的使用量
时间:2008-05-23 来源:liyf0371
#!/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" | sed "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 root < $FS_LOGFILE
fi
exit 0
#
# 目的:监视文件系统,如果使用量大于$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" | sed "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 root < $FS_LOGFILE
fi
exit 0
相关阅读 更多 +