Below is a simple script to monitor and inform of impending full disks. It was written on a AIX box, but should run on any *nix version.
#!/usr/bin/ksh
#
#@(#) Check filesystem space -
#@(#) used to automate the monitoring of filesystems to
#@(#) confirm that they do not pass a pre-defined threshold.
#
# This job is set up in cron to run on a regular basis.
# It monitors space in directories, making sure that free space
# does not fall below pre-defined thresholds.
#
if (( $FREE_SPACE < $LOW_WATER_MARK))
then
(( MB_FREE = $FREE_SPACE / 1024 ))
FILE_NAME="$TMP`echo $FILESYS | sed 's/\//\./g'`"
if [ ! -s $FILE_NAME ]
then
# If the log file doesn't exist, then check the filesystem one more
# time before paging the administrator
RE_CHK_FILE_SPC
else
# If the log file exists, then just log that it was still full at this
# time, but don't do any more (unless /tmp is the file that's full and
# the log could not be created.
date >> $FILE_NAME
fi
fi
}
if (( $FREE_SPACE < $LOW_WATER_MARK))
then
(( MB_FREE = $FREE_SPACE / 1024 ))
FILE_NAME="$TMP`echo $FILESYS | sed 's/\//\./g'`"
MESSAGE="Only $MB_FREE MB free in filesystem - $FILESYS - on $HOSTNAME"
# Comment out the next line if you do not have any paging software
# installed.
echo "$MESSAGE" | $PAGE UNIX_CRITICAL
# The following lines open the log file and save the message. This
# file is used to check against each time the script is run. If
# the log file exists then it will not page again, until after the
# date changes
date > $FILE_NAME
echo "$MESSAGE" >> $FILE_NAME
# The following lines will be sent to the mailbox of the root user.
echo "PROGRAM: \t $PROGRAM\n"
echo "LOG FILE:\t $HOSTNAME:$FILE_NAME\n"
echo "MESSAGE: \t $MESSAGE\n"
echo "PAGED: \t UNIX_CRITICAL"
fi
}
############### MAIN
#
# The format of the following lines - are as follows:
# FUNCTION_NAME filesystem amount_free [%]
#
# Examples:
#
# CHK_FILE_SPC /tmp 10
# - check /tmp for 10 MB of free space
#
# CHK_FILE_SPC / 40 %
# - check / to see that there is 40 % of free space
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.