使用shell脚本进行服务器系统监控——文件系统监控(2)

释放双眼,带上耳机,听听看~!

#!/usr/bin/ksh

WORKFILE="/tmp/df.work" # Holds filesystem data

$WORKFILE              # Initialize to empty

OUTFILE="/tmp/df.outfile" # Output display file

$OUTFILE  # Initialize to empty

BINDIR="/usr/local/bin" # Local bin directory
THISHOST=

1
1`

hostname

1
1`

 # Hostname of this machine
FSMAX="85"              # Max. FS percentage value

EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o #, comments

function load_EXCEPTIONS_file
{
cat $EXCEPTIONS |  grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
}

function check_exceptions
{

# set -x # Uncomment to debug this function

while read FSNAME NEW_MAX # Feeding Ddata from Bottom of Loop!!!
do
if [[ $FSNAME = $FSMOUNT ]] # Correct /mount_point?
then    # Get rid of the % sign, if it exists!
NEW_MAX=$(echo $NEW_MAX | sed s//%//g)

                if [ $FSVALUE -gt $NEW_MAX ]
then #  Over Limit…Return a "0", zero
return 0 # FOUND MAX OUT – Return 0
fi
fi

done < $DATA_EXCEPTIONS # Feed from the bottom of the loop!!

return 1 # Not found in File
}

######## START OF MAIN #############

[[ -s $EXCEPTIONS ]] && load_EXCEPTIONS_file

# Get the data of interest by stripping out the
# /cdrom row and keeping columns 1, 5 and 6

df -k | tail +2 | egrep -v '/cdrom' /
| awk '{print $1, $5, $6}' > $WORKFILE

# Loop through each line of the file and compare column 2

while read FSDEVICE FSVALUE FSMOUNT
do
# Strip out the % sign if it exists
FSVALUE=$(echo $FSVALUE | sed s//%//g) # Remove the % sign
if [[ -s $EXCEPTIONS ]] # Do we have a non-empty file?
then # Found it!

        # Look for the current $FSMOUNT value in the file
# using the check_exceptions function defined above.

        check_exceptions
RC=$?
if [ $RC -eq 0 ] # Found it Exceeded!!
then
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" /
>> $OUTFILE
elif [ $RC -eq 1 ] # Not founf in exceptions file, use defaults
then
if [ $FSVALUE -gt $FSMAX ] # Use Script Default
then
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" /
>> $OUTFILE
fi
fi
else # No exceptions file use the script default
if [ $FSVALUE -gt $FSMAX ] # Use Script Default
then
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" /
>> $OUTFILE
fi
fi
done < $WORKFILE # Feed the while loop from the bottom…

# Display output if anything is exceeded…

if [[ -s $OUTFILE ]]then      echo "/nFull Filesystem(s) on $THISHOST/n"      cat $OUTFILE      printfi 

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

node.js – JWT有效负载应该有多少信息?

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索