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

#!/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
THISHOST=`hostname` # Hostname of this machine
MIN_MB_FREE="50MB"     # Min. MB of Free FS Space

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

# Format Variables
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))

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

while read FSDEVICE FSMB_FREE FSMOUNT
do
      FSMB_FREE=$(echo $FSMB_FREE | sed s/MB//g) # Remove the "MB"
      if (( $FSMB_FREE < $MIN_MB_FREE ))
      then
          (( FS_FREE_OUT = $FSMB_FREE / 1000 ))
          echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" /
                >> $OUTFILE
      fi
done < $WORKFILE

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


原文链接: http://blog.csdn.net/jaminwm/article/details/1507957

你可能感兴趣的:(使用shell脚本进行服务器系统监控——文件系统监控(3))