Cover V04, I06
Article
Figure 1
Figure 2
Figure 3
Listing 1
Listing 10
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6
Listing 7
Listing 8
Listing 9

nov95.tar


Listing 3: dskmon.ksh--Script for filesystem space monitoring

#!/bin/ksh
#===================================================
# "@(#)dskmon.ksh"
#
# Checks filesystems and logs any that exceed the
# specified percentage used. There are 2 limits
# provided, the low file limit and the high file
# limit.
# Separate configuration parameters can be set for
# each of the limits.
#
# Author :
#       Ravindra Nemlekar and Jeffrey Soto
#
#===================================================

BINDIR=/usr/local/admin/sysmon
BASEDIR=/usr/local/admin/sysmon
CONDITION_NAME=Condition.FILE_SYSTEM_FULL
CONDITIONDIR=$BASEDIR/Condition.FILE_SYSTEM_FULL
# Pick up the Condition specific data
if [ -d $BASEDIR/config.$CONDITION_NAME ] ; then
CONFIGDIR=$BASEDIR/config.$CONDITION_NAME
else
CONFIGDIR=$BASEDIR
fi
SERVER_LIST=$CONFIGDIR/monlist
tempfile=/tmp/dskmon.$$
umask 0

touch $tempfile

cd $BASEDIR/hosts
for server in `cat "$SERVER_LIST" | grep -v \#`
do
# Process machine only if it is present in
# the master list.
$BASEDIR/check_in_master_list.ksh $server \
$BASEDIR/MASTER_LIST
if [ 0 -ne $? ] ; then
continue # Ignore this host
fi
# Check if the server is reachable
$BINDIR/check_alive.ksh $server
if [ "$?" != 0 ]
then
# Server cannot be rsh'ed. Don't proceed !!
continue
fi  # Check the filesystems
if [ 4 = "$(uname -r | cut -c1)" ] ; then
# SunOS 4.x
rsh -n $server df -t 4.2 | awk '{ \
printf("%s:%s:%s:%d\n", $1, $5, $6, NR) }' > $tempfile
else
# Solaris
rsh -n $server df -k | awk \
'{ printf("%s:%s:%s:%d\n", $1, $5, $6, NR) }' \
> $tempfile
fi
CONFIGS=/dev/null
# Read this for each host so that each
# one gets the initialized parameters
if [ -f $BASEDIR/config.generic ] ; then
# Read the global file first
. $BASEDIR/config.generic
fi
if [ -f $BASEDIR/config.Condition.\
FILE_SYSTEM_FULL/config.generic ] ; then
# read the condition specific global file
. $BASEDIR/config.Condition.\
FILE_SYSTEM_FULL/config.generic
fi
# Global level Configuration for each filesystem
if [ -f $BASEDIR/config.Condition.\
FILE_SYSTEM_FULL/config.filesystems ] ; then
CONFIGS="$BASEDIR/config.Condition.\
FILE_SYSTEM_FULL/config.filesystems $CONFIGS"
fi
# Low water mark for filesystem full
if [ -f $BASEDIR/config.Condition.\
LOW_FILE_LIMIT/config.generic ] ; then
. $BASEDIR/config.Condition.\
LOW_FILE_LIMIT/config.generic
fi
# High water mark for filesystem full
if [ -f $BASEDIR/config.Condition.\
HIGH_FILE_LIMIT/config.generic ] ; then
. $BASEDIR/config.Condition.\
HIGH_FILE_LIMIT/config.generic
fi
# Read the condition specific host specific files
if [ -f $server/config.Condition.\
LOW_FILE_LIMIT ] ; then
. $server/config.Condition.LOW_FILE_LIMIT
fi
if [ -f $server/config.Condition.\
HIGH_FILE_LIMIT ] ; then
. $server/config.Condition.HIGH_FILE_LIMIT
fi
# Configuration for each filesystem for host
if [ -f $server/config.filesystems ] ; then
CONFIGS="$server/config.filesystems $CONFIGS"
fi
LOW_FILE_LIMIT=${LOW_FILE_LIMIT:-80}
HIGH_FILE_LIMIT=${HIGH_FILE_LIMIT:-95}
# Store these two values since they will be
# reset for each Filesystem.
LOW=$LOW_FILE_LIMIT
HIGH=$HIGH_FILE_LIMIT
# Process the output of "df".
# Check the usage of each filesystem and
# check whether it exceeds the low or high
# limit.
for filesystem in $(cat $tempfile | \
grep -v Filesystem)
do
LOW_FILE_LIMIT=$LOW
HIGH_FILE_LIMIT=$HIGH
filesys=`echo $filesystem | awk -F: \
'{print $1}'`
pct_dsk_used=`echo $filesystem |awk -F:\
'{print $2}' | awk -F% '{print $1}'`
mount_point=`echo $filesystem | awk -F:\
'{ print $3}'`

LOW_LIMIT=$($BINDIR/check_filesystem_limit.\
ksh "LOW" $mount_point $CONFIGS)
if [ "$LOW_LIMIT" ] ; then
LOW_FILE_LIMIT=$LOW_LIMIT
fi

HIGH_LIMIT=$($BINDIR/check_filesystem_limit.\
ksh "HIGH" $mount_point $CONFIGS)
if [ "$HIGH_LIMIT" ] ; then
HIGH_FILE_LIMIT=$HIGH_LIMIT
fi
low_dsk_stat=`expr $pct_dsk_used -\
$LOW_FILE_LIMIT`
high_dsk_stat=`expr $pct_dsk_used - \
$HIGH_FILE_LIMIT`
file_id=`echo $filesystem | awk -F: \
'{ print $4}'`
if [ "$high_dsk_stat" -gt  0  ] ; then
echo "$(date "+ %H:%M") $server
$filesys\
$mount_point $pct_dsk_used% full" \
> $BASEDIR/hosts/$server/Condition.HIGH_FILE_LIMIT
elif [ "$low_dsk_stat" -gt  0  ] ; then
echo "$(date "+ %H:%M") $server \
$filesys $mount_point $pct_dsk_used% full" \
> $BASEDIR/hosts/$server/Condition.LOW_FILE_LIMIT
if [ -f $BASEDIR/hosts/$server/\
Condition.HIGH_FILE_LIMIT ] ; then
fgrep "$filesys" $BASEDIR/hosts/\
$server/Condition.HIGH_FILE_LIMIT >/dev/null
if [ $? -eq 0 ] ; then
echo "$server: $mount_point under \
${HIGH_FILE_LIMIT}%" > $BASEDIR/hosts/$server/\
End.Condition.HIGH_FILE_LIMIT
fi
fi
else	# Filesystem within limit
if [ -f $BASEDIR/hosts/$server/\
Condition.HIGH_FILE_LIMIT ] ; then
fgrep "$filesys" $BASEDIR/hosts/\
$server/Condition.HIGH_FILE_LIMIT >/dev/null
if [ $? -eq 0 ] ; then
echo "$server: $mount_point under \

${HIGH_FILE_LIMIT}%" > $BASEDIR/hosts/$server/\
End.Condition.HIGH_FILE_LIMIT
fi
fi
if [ -f $BASEDIR/hosts/$server/\
Condition.LOW_FILE_LIMIT ] ; then
fgrep "$filesys" $BASEDIR/hosts/\
$server/Condition.LOW_FILE_LIMIT >/dev/null
if [ $? -eq 0 ] ; then
echo "$server: $mount_point under\
${LOW_FILE_LIMIT}%" > $BASEDIR/hosts/$server/\
End.Condition.LOW_FILE_LIMIT
fi
fi
fi
done # End of processing of server's filesystems

/bin/rm -f $tempfile  # Clean up
done             # End of processing this server

# End of File