initial commit
This commit is contained in:
53
chapter17/fs_mon_AIX.ksh
Executable file
53
chapter17/fs_mon_AIX.ksh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX
|
||||
#
|
||||
# REV LIST:
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
|
||||
| awk '{print $1, $4, $7}' > $WORKFILE
|
||||
|
||||
# Loop through each line of the file and compare column 2
|
||||
|
||||
while read FSDEVICE FSVALUE FSMOUNT
|
||||
do
|
||||
FSVALUE=$(echo "$FSVALUE" | sed s/\%//g) # Remove the % sign
|
||||
if [ "$FSVALUE" -gt "$FSMAX" ]
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
61
chapter17/fs_mon_AIX_MBFREE.ksh
Executable file
61
chapter17/fs_mon_AIX_MBFREE.ksh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.5.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
|
||||
| awk '{print $1, $3, $7}' > $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 # Feed the while loop from the bottom!!
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
131
chapter17/fs_mon_AIX_MBFREE_excep.ksh
Executable file
131
chapter17/fs_mon_AIX_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX_MBFREE_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
# Do an NFS sanity check
|
||||
echo $FSNAME | grep ":" >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]] # Check for empty/null
|
||||
then
|
||||
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
|
||||
if [[ $FSNAME = $FSMOUNT ]]
|
||||
then
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
else
|
||||
return 2 # Found OK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 3 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Load the $EXCEPTIONS file if it exists
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
# Ignore all lines beginning with a pound sign, #
|
||||
# and omit all blank lines
|
||||
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
|
||||
fi
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
|
||||
| awk '{print $1, $3, $7}' > $WORKFILE
|
||||
|
||||
# Format Variables for the proper MB value
|
||||
(( 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
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
check_exceptions
|
||||
RC="$?"
|
||||
if (( RC == 1 )) # Found out of exceptions limit
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" >> $OUTFILE
|
||||
elif (( $RC == 2 )) # Found in exceptions to be OK
|
||||
then # Just a sanity check - We really do nothing here...
|
||||
# The colon, :, is a NO-OP operator in KSH
|
||||
|
||||
: # No-Op - Do Nothing!
|
||||
|
||||
elif [ $RC -eq 3 ] # Not found in the exceptions file
|
||||
then
|
||||
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 only has ${FS_FREE_OUT}MB Free" >> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
else # No Exceptions file use the script default
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
280
chapter17/fs_mon_AIX_PC_MBFREE.ksh
Executable file
280
chapter17/fs_mon_AIX_PC_MBFREE.ksh
Executable file
@@ -0,0 +1,280 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX_PC_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB)
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N)
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
287
chapter17/fs_mon_AIX_PC_MBFREE_excep.ksh
Executable file
287
chapter17/fs_mon_AIX_PC_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,287 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX_PC_MBFREE_excep.ksh`
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
>$DATA_EXCEPTIONS
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB) # Use Megabytes of free space to test
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
# using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N) # Test type not specified in exception file, use default
|
||||
|
||||
# Inform the user of the exceptions file error...
|
||||
echo "\nERROR: Missing testing type in exceptions file"
|
||||
echo " for the $FSMOUNT mount point. A \"%\" or"
|
||||
echo " \"MB\" must be a suffix to the numerical"
|
||||
echo " entry. Using script default values...\n"
|
||||
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
# and omit all blank lines
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
# Remove the "MB", if it exists
|
||||
FSMB_FREE=$(echo $FSMB_FREE | sed s/MB//g)
|
||||
typeset -i FSMB_FREE
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
127
chapter17/fs_mon_AIX_excep.ksh
Executable file
127
chapter17/fs_mon_AIX_excep.ksh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_AIX_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
#
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
|
||||
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=`hostname` # Hostname of this machine
|
||||
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o #, comments
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function load_EXCEPTIONS_file
|
||||
{
|
||||
# Ignore any line that begins with a pound sign, #
|
||||
# and omit all blank lines
|
||||
|
||||
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 #############
|
||||
####################################
|
||||
|
||||
# If there is an exceptions file...load it...
|
||||
|
||||
[[ -s $EXCEPTIONS ]] && load_EXCEPTIONS_file
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc' \
|
||||
| awk '{print $1, $4, $7}' > $WORKFILE
|
||||
|
||||
# Loop through each line of the file and compare column 2
|
||||
|
||||
while read FSDEVICE FSVALUE FSMOUNT
|
||||
do # Feeding the while loop from the BOTTOM!!
|
||||
|
||||
# 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=$? # Get the return code from the function
|
||||
if [ $RC -eq 0 ] # Found Exceeded in Exceptions File!!
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 1 ] # Not found in exceptions, 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
|
||||
print
|
||||
fi
|
||||
381
chapter17/fs_mon_ALL_OS.ksh
Executable file
381
chapter17/fs_mon_ALL_OS.ksh
Executable file
@@ -0,0 +1,381 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_ALL_OS.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 09-25-2007
|
||||
# REV: 6.0.P
|
||||
#
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which are defined as .exceeding. the MAX_PERCENT value.
|
||||
# A message is displayed for all .full. filesystems.
|
||||
#
|
||||
# PLATFORM: AIX, Linux, HP-UX, OpenBSD, and Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an .auto-detection. but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Added code to allow this script to be executed on
|
||||
# AIX, Linux, HP-UX, and Solaris
|
||||
#
|
||||
# Randy Michael - 09=25=2007
|
||||
# Added code for OpenBSD support
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to be multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
###### SHELL SPECIFIC VARIABLES ######
|
||||
|
||||
# Set the correct usage for the echo command for found $SHELL
|
||||
|
||||
case $SHELL in
|
||||
*/bin/bash) ECHO="echo -e"
|
||||
;;
|
||||
*/bin/ksh) ECHO="echo"
|
||||
;;
|
||||
*/bin/sh) ECHO="echo -e"
|
||||
;;
|
||||
*) ECHO="echo"
|
||||
;;
|
||||
esac
|
||||
|
||||
######################################
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
######################################
|
||||
|
||||
function get_OS_info
|
||||
{
|
||||
# For a few commands it is necessary to know the OS and its level
|
||||
# to execute the proper command syntax. This will always return
|
||||
# the OS in UPPERCASE
|
||||
|
||||
typeset -u OS # Use the UPPERCASE values for the OS variable
|
||||
OS=`uname` # Grab the Operating system, i.e. AIX, HP-UX
|
||||
print $OS # Send back the UPPERCASE value
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any .:..
|
||||
# If this is found it is actually an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
$ECHO $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$($ECHO $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
$ECHO $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $($ECHO $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for '%' Character...Set IN_FILE=PC, for %
|
||||
$ECHO $FSLIMIT | grep '%' >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$($ECHO $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB) # Use MB of Free Space Method
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$($ECHO $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the 'MB' if it exists
|
||||
FSLIMIT=$($ECHO $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem 'MB' limit
|
||||
if (( FSLIMIT >= 0 && FSLIMIT < FSSIZE ))
|
||||
then
|
||||
if (( FSMB_FREE < FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
# using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Invalid filesystem MAX for\
|
||||
$FSMOUNT - $FSLIMIT"
|
||||
$ECHO " Exceptions file value must be less\
|
||||
than or"
|
||||
$ECHO " equal to the size of the filesystem\
|
||||
measured"
|
||||
$ECHO " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Null value specified in exceptions\
|
||||
file"
|
||||
$ECHO " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC) # Use Filesystem %Used Method
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( FSLIMIT >= 0 && FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Invalid percentage for $FSMOUNT -\
|
||||
$FSLIMIT"
|
||||
$ECHO " Exceptions file values must be"
|
||||
$ECHO " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Null value specified in exceptions\
|
||||
file"
|
||||
$ECHO " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N) # Method Not Specified - Use Script Defaults
|
||||
if (( FSSIZE >= FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( FSMB_FREE < MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
# using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g) # Remove %
|
||||
FSLIMIT=$($ECHO $FSLIMIT | sed s/\%//g) # Remove %
|
||||
if (( PC_USED > FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
$ECHO "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ignore any line that begins with a pound sign, #
|
||||
# and omit all blank lines
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_AIX_FS_data
|
||||
{
|
||||
|
||||
df -k | tail +2 | egrep -v "/dev/cd[0-9]|/proc" \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_HP_UX_FS_data
|
||||
{
|
||||
|
||||
bdf | tail +2 | egrep -v "/cdrom" \
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_LINUX_FS_data
|
||||
{
|
||||
|
||||
df -k | tail -n +2 | egrep -v "/cdrom"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_OpenBSD_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v "/mnt/cdrom"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_Solaris_FS_data
|
||||
{
|
||||
|
||||
df -k | tail +2 | egrep -v "/dev/fd|/etc/mnttab|/proc"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
# Query the operating system to find the Unix flavor, then
|
||||
# load the correct filesystem data for the resident OS
|
||||
|
||||
case $(get_OS_info) in
|
||||
AIX) # Load filesystem data for AIX
|
||||
load_AIX_FS_data
|
||||
;;
|
||||
HP-UX) # Load filesystem data for HP-UX
|
||||
load_HP_UX_FS_data
|
||||
;;
|
||||
LINUX) # Load filesystem data for Linux
|
||||
load_LINUX_FS_data
|
||||
;;
|
||||
OPENBSD) # Load filesystem data for OpenBSD
|
||||
load_OpenBSD_FS_data
|
||||
;;
|
||||
SUNOS) # Load filesystem data for Solaris
|
||||
load_Solaris_FS_data
|
||||
;;
|
||||
*) # Unsupported in script
|
||||
$ECHO "\nUnsupported Operating System for this Script...EXITING\n"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
# Do we have a nonzero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a nonempty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = FSMB_FREE / 1000 ))
|
||||
$ECHO "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" >> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
$ECHO "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing. A ':' is a no-op!
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( FSSIZE >= FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$($ECHO $MAX_PERCENT | sed s/\%//g)
|
||||
if (( PC_USED > MAX_PERCENT ))
|
||||
then
|
||||
$ECHO "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
else # NO $EXCEPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( FSSIZE >= FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$($ECHO $MAX_PERCENT | sed s/\%//g)
|
||||
if (( PC_USED > MAX_PERCENT ))
|
||||
then
|
||||
$ECHO "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE # Feed the while loop from the bottom!!!!!
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
|
||||
278
chapter17/fs_mon_COMBO.ksh
Executable file
278
chapter17/fs_mon_COMBO.ksh
Executable file
@@ -0,0 +1,278 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB)
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N)
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
52
chapter17/fs_mon_HPUX.ksh
Executable file
52
chapter17/fs_mon_HPUX.ksh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_HPUX.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# REV LIST:
|
||||
#
|
||||
# PLATFORM: HP-UX
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 5 and 6
|
||||
|
||||
bdf | 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
|
||||
FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign
|
||||
if [ $FSVALUE -gt $FSMAX ]
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
59
chapter17/fs_mon_HPUX_MBFREE.ksh
Executable file
59
chapter17/fs_mon_HPUX_MBFREE.ksh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_HPUX_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.5.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: HP-UX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 4 and 6
|
||||
|
||||
bdf | 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
|
||||
129
chapter17/fs_mon_HPUX_MBFREE_excep.ksh
Executable file
129
chapter17/fs_mon_HPUX_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_HPUX_MBFREE_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: HP-UX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
# Do an NFS sanity check
|
||||
echo $FSNAME | grep ":" >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
|
||||
then
|
||||
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
|
||||
if [[ $FSNAME = $FSMOUNT ]]
|
||||
then
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
else
|
||||
return 2 # Found OK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 3 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
# Ignore all line beginning with a pound sign, #.
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
fi
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 4 and 6
|
||||
|
||||
bdf | tail +2 | egrep -v '/cdrom' \
|
||||
| awk '{print $1, $4, $6}' > $WORKFILE
|
||||
|
||||
# Format Variables for the proper MB value
|
||||
(( 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
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
check_exceptions
|
||||
RC="$?"
|
||||
if [ $RC -eq 1 ] # Found out of exceptions limit
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 2 ] # Found in exceptions to be OK
|
||||
then # Just a sanity check - We really do nothing here...
|
||||
# The colon, :, is a NO-OP operator in KSH
|
||||
|
||||
: # No-Op - Do Nothing!
|
||||
|
||||
elif [ $RC -eq 3 ] # Not found in the exceptions file
|
||||
then
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
else # No Exceptions file use the script default
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
280
chapter17/fs_mon_HPUX_PC_MBFREE.ksh
Executable file
280
chapter17/fs_mon_HPUX_PC_MBFREE.ksh
Executable file
@@ -0,0 +1,280 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_HPUX_PC_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: HP-UX
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB)
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N)
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
bdf | tail +2 | egrep -v '/cdrom' \
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
113
chapter17/fs_mon_HPUX_excep.ksh
Executable file
113
chapter17/fs_mon_HPUX_excep.ksh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_HPUX_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: HP-UX
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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=`hostname` # Hostname of this machine
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
# Define a data file
|
||||
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out"
|
||||
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
|
||||
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 #############
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 5 and 6
|
||||
|
||||
bdf | 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
|
||||
if [ $? -eq 0 ] # Found it Exceeded!!
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
else # Not exceeded in the file use the script default
|
||||
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
|
||||
print
|
||||
fi
|
||||
52
chapter17/fs_mon_LINUX.ksh
Executable file
52
chapter17/fs_mon_LINUX.ksh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_LINUX.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: Linux
|
||||
#
|
||||
# REV LIST:
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out the rows that
|
||||
# are not monitored 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
|
||||
FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign
|
||||
if [ $FSVALUE -gt $FSMAX ]
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
59
chapter17/fs_mon_LINUX_MBFREE.ksh
Executable file
59
chapter17/fs_mon_LINUX_MBFREE.ksh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_LINUX_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.5.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: Linux
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 4 and 6
|
||||
|
||||
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
|
||||
129
chapter17/fs_mon_LINUX_MBFREE_excep.ksh
Executable file
129
chapter17/fs_mon_LINUX_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_LINUX_MBFREE_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: Linux
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
# Do an NFS sanity check
|
||||
echo $FSNAME | grep ":" >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
|
||||
then
|
||||
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
|
||||
if [[ $FSNAME = $FSMOUNT ]]
|
||||
then
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
else
|
||||
return 2 # Found OK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 3 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
# Ignore all line beginning with a pound sign, #.
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
fi
|
||||
|
||||
# Get the data of interest by stripping out the
|
||||
# /cdrom row and keeping columns 1, 4 and 6
|
||||
|
||||
df -k | tail +2 | egrep -v '/cdrom' \
|
||||
| awk '{print $1, $4, $6}' > $WORKFILE
|
||||
|
||||
# Format Variables for the proper MB value
|
||||
(( 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
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
check_exceptions
|
||||
RC="$?"
|
||||
if [ $RC -eq 1 ] # Found out of exceptions limit
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 2 ] # Found in exceptions to be OK
|
||||
then # Just a sanity check - We really do nothing here...
|
||||
# The colon, :, is a NO-OP operator in KSH
|
||||
|
||||
: # No-Op - Do Nothing!
|
||||
|
||||
elif [ $RC -eq 3 ] # Not found in the exceptions file
|
||||
then
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
else # No Exceptions file use the script default
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
280
chapter17/fs_mon_LINUX_PC_MBFREE.ksh
Executable file
280
chapter17/fs_mon_LINUX_PC_MBFREE.ksh
Executable file
@@ -0,0 +1,280 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_LINUX_PC_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: Linux
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB)
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N)
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/cdrom' \
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
113
chapter17/fs_mon_LINUX_excep.ksh
Executable file
113
chapter17/fs_mon_LINUX_excep.ksh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_LINUX_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: Linux
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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=`hostname` # Hostname of this machine
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
# Define a data file
|
||||
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out"
|
||||
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
|
||||
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 #############
|
||||
|
||||
# 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
|
||||
if [ $? -eq 0 ] # Found it Exceeded!!
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
else # Not exceeded in the file use the script default
|
||||
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
|
||||
print
|
||||
fi
|
||||
57
chapter17/fs_mon_MBFREE.ksh
Executable file
57
chapter17/fs_mon_MBFREE.ksh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.5.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $3, $7}' > $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 % sign
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only 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
|
||||
127
chapter17/fs_mon_MBFREE_excep.ksh
Executable file
127
chapter17/fs_mon_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
# Do an NFS sanity check
|
||||
echo $FSNAME | grep ":" >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
|
||||
if [[ $FSNAME = $FSMOUNT ]]
|
||||
then
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
else
|
||||
return 2 # Found OK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 3 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
# Ignore all line beginning with a pound sign, #.
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
fi
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $3, $7}' > $WORKFILE
|
||||
|
||||
# Format Variables for the proper MB value
|
||||
(( 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
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
check_exceptions
|
||||
RC="$?"
|
||||
if [ $RC -eq 1 ] # Found out of exceptions limit
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 2 ] # Found in exceptions to be OK
|
||||
then # Just a sanity check - We really do nothing here...
|
||||
# The colon, :, is a NO-OP operator in KSH
|
||||
|
||||
: # No-Op - Do Nothing!
|
||||
|
||||
elif [ $RC -eq 3 ] # Not found in the exceptions file
|
||||
then
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
else # No Exceptions file use the script default
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
52
chapter17/fs_mon_SUNOS.ksh
Executable file
52
chapter17/fs_mon_SUNOS.ksh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_SUNOS.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: SUN Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out rows
|
||||
# to be ignored and keeping columns 1, 5 and 6
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/fd|/etc/mnttab|/proc|/cdrom' \
|
||||
| awk '{print $1, $5, $6}' > $WORKFILE
|
||||
|
||||
# Loop through each line of the file and compare column 2
|
||||
|
||||
while read FSDEVICE FSVALUE FSMOUNT
|
||||
do
|
||||
FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign
|
||||
if [ $FSVALUE -gt $FSMAX ]
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
59
chapter17/fs_mon_SUNOS_MBFREE.ksh
Executable file
59
chapter17/fs_mon_SUNOS_MBFREE.ksh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_SUNOS_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 1.5.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: SUN Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
# Get the data of interest by stripping out the rows
|
||||
# to not monitor and keeping columns 1, 4 and 6
|
||||
|
||||
df -k | tail +2 | egrep -v 'fd|mnttab|proc|cdrom|objfs' \
|
||||
| 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
|
||||
129
chapter17/fs_mon_SUNOS_MBFREE_excep.ksh
Executable file
129
chapter17/fs_mon_SUNOS_MBFREE_excep.ksh
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_SUNOS_MBFREE_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the $MIN_MB_FREE value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: SUN Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
# Do an NFS sanity check
|
||||
echo $FSNAME | grep ":" >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
|
||||
then
|
||||
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
|
||||
if [[ $FSNAME = $FSMOUNT ]]
|
||||
then
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
else
|
||||
return 2 # Found OK
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 3 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
# Ignore all line beginning with a pound sign, #.
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
fi
|
||||
|
||||
# Get the data of interest by stripping out rows that
|
||||
# are not monitored and keeping columns 1, 4 and 6
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/fd|/etc/mnttab|/proc|/cdrom' \
|
||||
| awk '{print $1, $4, $6}' > $WORKFILE
|
||||
|
||||
# Format Variables for the proper MB value
|
||||
(( 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
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then
|
||||
check_exceptions
|
||||
RC="$?"
|
||||
if [ $RC -eq 1 ] # Found out of exceptions limit
|
||||
then
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 2 ] # Found in exceptions to be OK
|
||||
then # Just a sanity check - We really do nothing here...
|
||||
# The colon, :, is a NO-OP operator in KSH
|
||||
|
||||
: # No-Op - Do Nothing!
|
||||
|
||||
elif [ $RC -eq 3 ] # Not found in the exceptions file
|
||||
then
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
else # No Exceptions file use the script default
|
||||
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 only has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
280
chapter17/fs_mon_SUNOS_PC_MBFREE.ksh
Executable file
280
chapter17/fs_mon_SUNOS_PC_MBFREE.ksh
Executable file
@@ -0,0 +1,280 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_SUNOS_PC_MBFREE.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 4.3.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the MAX_PERCENT value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: SUN Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
# Randy Michael - 08-27-2007
|
||||
# Changed the code to use MB of free space instead of
|
||||
# the %Used method.
|
||||
#
|
||||
# Randy Michael - 08-27-2007
|
||||
# Added code to allow you to override the set script default
|
||||
# for MIN_MB_FREE of FS Space
|
||||
#
|
||||
# Randy Michael - 08-28-2007
|
||||
# Changed the code to handle both %Used and MB of Free Space.
|
||||
# It does an "auto-detection" but has override capability
|
||||
# of both the trigger level and the monitoring method using
|
||||
# the exceptions file pointed to by the $EXCEPTIONS variable
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty
|
||||
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
|
||||
EXCEPT_FILE="N" # Assume no $EXCEPTIONS FILE
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
|
||||
MIN_MB_FREE="100MB" # Min. MB of Free FS Space
|
||||
MAX_PERCENT="85%" # Max. FS percentage value
|
||||
FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free
|
||||
|
||||
|
||||
###### FORMAT VARIABLES HERE ######
|
||||
|
||||
# Both of these variables need to multiplied by 1024 blocks
|
||||
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
|
||||
(( FSTRIGGER = $(echo $FSTRIGGER | sed s/MB//g) * 1024 ))
|
||||
|
||||
####### DEFINE FUNCTIONS HERE ########
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any ":".
|
||||
# If this is found it is actaully an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
echo $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$(echo $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
echo $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $(echo $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for "%" Character...Set IN_FILE=PC, for %
|
||||
echo $FSLIMIT | grep "%" >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$(echo $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB)
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$(echo $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the "MB" if it exists
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem "MB" limit
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT < $FSSIZE ))
|
||||
then
|
||||
if (( $FSMB_FREE < $FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid filesystem MAX for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file value must be less than or"
|
||||
echo " equal to the size of the filesystem measured"
|
||||
echo " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC)
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( $FSLIMIT >= 0 && $FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Invalid percentage for $FSMOUNT - $FSLIMIT"
|
||||
echo " Exceptions file values must be"
|
||||
echo " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
echo "\nERROR: Null value specified in excepeptions file"
|
||||
echo " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N)
|
||||
# Method Not Specified - Use Script Defaults
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( $FSMB_FREE < $MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g) # Remove the %
|
||||
FSLIMIT=$(echo $FSLIMIT | sed s/\%//g) # Remove the %
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
echo "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
####################################
|
||||
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/dev/fd|/etc/mnttab|/proc|/cdrom' \
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
####################################
|
||||
######### START OF MAIN ############
|
||||
####################################
|
||||
|
||||
load_FS_data
|
||||
|
||||
# Do we have a non-zero size $EXCEPTIONS file?
|
||||
|
||||
if [[ -s $EXCEPTIONS ]]
|
||||
then # Found a non-empty $EXCEPTIONS file
|
||||
|
||||
load_EXCEPTIONS_data
|
||||
EXCEP_FILE="Y"
|
||||
fi
|
||||
|
||||
while read FSDEVICE FSSIZE FSMB_FREE PC_USED FSMOUNT
|
||||
do
|
||||
if [[ $EXCEP_FILE = "Y" ]]
|
||||
then
|
||||
check_exceptions
|
||||
CE_RC="$?" # Check Exceptions Return Code (CE_RC)
|
||||
|
||||
case $CE_RC in
|
||||
1) # Found exceeded in exceptions file by MB Method
|
||||
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT has ${FS_FREE_OUT}MB Free" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
2) # Found exceeded in exceptions file by %Used method
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
;;
|
||||
3) # Found OK in exceptions file
|
||||
: # NO-OP Do Nothing
|
||||
;;
|
||||
|
||||
4) # Not found in exceptions file - Use Default Triggers
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
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
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
else # NO $EXECPTIONS FILE USE DEFAULT TRIGGER VALUES
|
||||
|
||||
if (( $FSSIZE >= $FSTRIGGER ))
|
||||
then # This is a "large" filesystem - Use MB Free Method
|
||||
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
|
||||
else # This is a standard filesystem - Use % Used Method
|
||||
PC_USED=$(echo $PC_USED | sed s/\%//g)
|
||||
MAX_PERCENT=$(echo $MAX_PERCENT | sed s/\%//g)
|
||||
if (( $PC_USED > $MAX_PERCENT ))
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${PC_USED}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done < $WORKFILE
|
||||
|
||||
display_output
|
||||
|
||||
# End of Script
|
||||
113
chapter17/fs_mon_SUNOS_excep.ksh
Executable file
113
chapter17/fs_mon_SUNOS_excep.ksh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon_SUNOS_excep.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: SUN Solaris
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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=`hostname` # Hostname of this machine
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
# Define a data file
|
||||
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out"
|
||||
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
|
||||
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 #############
|
||||
|
||||
# Get the data of interest by stripping out the rows that
|
||||
# are not monitored and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/fd|/etc/mnttab|/proc|/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
|
||||
if [ $? -eq 0 ] # Found it Exceeded!!
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
else # Not exceeded in the file use the script default
|
||||
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
|
||||
print
|
||||
fi
|
||||
113
chapter17/fs_mon_excep.ksh
Executable file
113
chapter17/fs_mon_excep.ksh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 2.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX, at least
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
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=`hostname` # Hostname of this machine
|
||||
FSMAX="85" # Max. FS percentage value
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
# Define a data file
|
||||
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out"
|
||||
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
|
||||
while read FSNAME NEW_MAX # Feeding Data 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 #############
|
||||
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $4, $7}' > $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
|
||||
if [ $? -eq 0 ] # Found it Exceeded!!
|
||||
then
|
||||
echo "$FSDEVICE mount on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
else # Not exceeded in the file use the script default
|
||||
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
|
||||
print
|
||||
fi
|
||||
182
chapter17/fs_mon_except_MB.ksh
Executable file
182
chapter17/fs_mon_except_MB.ksh
Executable file
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/ksh
|
||||
#
|
||||
# SCRIPT: fs_mon.ksh
|
||||
# AUTHOR: Randy Michael
|
||||
# DATE: 08-22-2007
|
||||
# REV: 3.1.P
|
||||
# PURPOSE: This script is used to monitor for full filesystems,
|
||||
# which is defined as "exceeding" the FSMAX value.
|
||||
# A message is displayed for all "full" filesystems.
|
||||
#
|
||||
# PLATFORM: AIX, at least
|
||||
#
|
||||
# REV LIST:
|
||||
# 08-23-2007 - Randy Michael
|
||||
# Added code to override the default FSMAX script threshold
|
||||
# using an "exceptions" file, defined by the $EXCEPTIONS
|
||||
# variable, that list /mount_point and NEW_MAX%
|
||||
#
|
||||
# 08-26-2007 - Randy Michael
|
||||
# Added code to check both %USED and MB of Free space
|
||||
# with auto detection to switch from %USED to MB Free
|
||||
# for filesystems of 3GB and greater.
|
||||
#
|
||||
# set -n # Uncomment to check syntax without any execution
|
||||
# set -x # Uncomment to debug this script
|
||||
#
|
||||
##### DEFINE FILES AND VARIABLES HERE ####
|
||||
|
||||
typeset -i FSTOTMB
|
||||
|
||||
WORKFILE="/tmp/df.work" # Holds filesystem data
|
||||
>$WORKFILE # Initialize to empty file
|
||||
OUTFILE="/tmp/df.outfile" # Output display file
|
||||
>$OUTFILE # Initialize to empty file
|
||||
BINDIR="/usr/local/bin" # Local bin directory
|
||||
THISHOST=`hostname` # Hostname of this machine
|
||||
FSMAX="85%" # Max. FS percentage value
|
||||
EXCEPTIONS="${BINDIR}/exceptions" # Overrides $FSMAX
|
||||
|
||||
MBSWITCH="1000MB" # Number of MB to switch from %USED to MB Free
|
||||
MBTRIGGER="40MB" # Minimum MB free before trigger
|
||||
|
||||
|
||||
####### DEFINE FUNCTIONS HERE #####
|
||||
|
||||
function check_exceptions
|
||||
{
|
||||
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
# Define a data file
|
||||
|
||||
DATA_EXCEPTIONS="/tmp/dfdata.out"
|
||||
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" > $DATA_EXCEPTIONS
|
||||
|
||||
while read FSNAME NEW_MAX # Feeding Ddata from Bottom of Loop!!!
|
||||
do
|
||||
if [[ "$FSNAME" = "$FSMOUNT" ]] # Correct /mount_point?
|
||||
then
|
||||
if (( $FSTOTMB >= $MBSWITCH ))
|
||||
then
|
||||
# MB Free Space - Get rid of "MB" if exists!
|
||||
NEW_MIN_MB=$(echo $NEW_MAX | sed s/MB//g)
|
||||
(( NEW_MIN_MB = $NEW_MIN_MB * 1024000 )) # In bytes
|
||||
|
||||
if (( $FSFREEMB < $NEW_MIN_MB ))
|
||||
then
|
||||
return 2 # Found below MB Trigger Level
|
||||
else
|
||||
return 3 # Found but OK
|
||||
fi
|
||||
else
|
||||
# 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
|
||||
fi
|
||||
|
||||
done < $DATA_EXCEPTIONS # Feed from the bottom of the loop!!
|
||||
|
||||
return 1 # Not found in File
|
||||
}
|
||||
|
||||
######## START OF MAIN #############
|
||||
|
||||
####### FORMAT VARIABLES ###########
|
||||
|
||||
# Get rib of the "MB" letters if they exist
|
||||
MBTRIGGER=$(echo $MBTRIGGER | sed s/MB//g )
|
||||
MBSWITCH=$(echo $MBSWITCH | sed s/MB//g )
|
||||
|
||||
# Get rid of the "%" if it exists
|
||||
FSMAX=$(echo $FSMAX | sed s/\%//g )
|
||||
|
||||
# Get an "actual" value in Mega Bytes
|
||||
(( MBSWITCH = $MBSWITCH * 1024000 ))
|
||||
(( MBTRIGGER = $MBTRIGGER * 1024000 ))
|
||||
|
||||
####################################
|
||||
# Get the data of interest by stripping out /dev/cd#,
|
||||
# /proc rows and keeping columns 1, 4 and 7
|
||||
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
|
||||
####################################
|
||||
# Loop through each line of the file and compare column 2
|
||||
|
||||
while read FSDEVICE FSTOTKB FSFREEKB FSVALUE FSMOUNT
|
||||
do
|
||||
# Strip out the % sign if it exists
|
||||
FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign
|
||||
(( FSTOTMB = $FSTOTKB * 1000 ))
|
||||
(( FSFREEMB = $FSFREEKB * 1000 ))
|
||||
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 by Percentage
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -eq 2 ] # Found it Exceeded by MB Free
|
||||
then
|
||||
(( FSFREEMB = $FSFREEMB / 1000000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FSFREEMB}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $RC -ne 3 ]
|
||||
then
|
||||
if (( $FSTOTMB >= $MBSWITCH ))
|
||||
then
|
||||
if (( $FSFREEMB < $MBTRIGGER )) # Use MB of Free Space?
|
||||
then
|
||||
(( FSFREEMB = $FSFREEMB / 1000000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FSFREEMB}MB Free" \
|
||||
>> $OUTFILE
|
||||
elif [ $FSVALUE -gt $FSMAX ] # Use Script Default of % Used
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else # No exceptions file use the script default
|
||||
if (( $FSTOTMB >= $MBSWITCH ))
|
||||
then
|
||||
if (( $FSFREEMB < $MBTRIGGER ))
|
||||
then
|
||||
(( FSFREEMB = $FSFREEMB / 1000000 ))
|
||||
echo "$FSDEVICE mounted on $FSMOUNT only has ${FSFREEMB}MB Free" \
|
||||
>> $OUTFILE
|
||||
fi
|
||||
else
|
||||
if [ $FSVALUE -gt $FSMAX ] # Use Script Default
|
||||
then
|
||||
echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
|
||||
>> $OUTFILE
|
||||
|
||||
fi
|
||||
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
|
||||
print
|
||||
fi
|
||||
119
chapter17/function_check_exceptions
Executable file
119
chapter17/function_check_exceptions
Executable file
@@ -0,0 +1,119 @@
|
||||
function check_exceptions
|
||||
{
|
||||
# set -x # Uncomment to debug this function
|
||||
|
||||
while read FSNAME FSLIMIT
|
||||
do
|
||||
IN_FILE="N"
|
||||
|
||||
# Do an NFS sanity check and get rid of any .:..
|
||||
# If this is found it is actually an error entry
|
||||
# but we will try to resolve it. It will only
|
||||
# work if it is an NFS cross mount to the same
|
||||
# mount point on both machines.
|
||||
$ECHO $FSNAME | grep ':' >/dev/null \
|
||||
&& FSNAME=$($ECHO $FSNAME | cut -d ':' -f2)
|
||||
|
||||
# Check for empty and null variable
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
if [[ $FSNAME = $FSMOUNT ]] # Found it!
|
||||
then
|
||||
# Check for "MB" Characters...Set IN_FILE=MB
|
||||
$ECHO $FSLIMIT | grep MB >/dev/null && IN_FILE="MB" \
|
||||
&& (( FSLIMIT = $($ECHO $FSLIMIT \
|
||||
| sed s/MB//g) * 1024 ))
|
||||
# check for '%' Character...Set IN_FILE=PC, for %
|
||||
$ECHO $FSLIMIT | grep '%' >/dev/null && IN_FILE="PC" \
|
||||
&& FSLIMIT=$($ECHO $FSLIMIT | sed s/\%//g)
|
||||
|
||||
case $IN_FILE in
|
||||
MB) # Use MB of Free Space Method
|
||||
# Up-case the characters, if they exist
|
||||
FSLIMIT=$($ECHO $FSLIMIT | tr '[a-z]' '[A-Z]')
|
||||
# Get rid of the 'MB' if it exists
|
||||
FSLIMIT=$($ECHO $FSLIMIT | sed s/MB//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z $FSLIMIT && $FSLIMIT != '' ]]
|
||||
then
|
||||
# Test for a valid filesystem 'MB' limit
|
||||
if (( FSLIMIT >= 0 && FSLIMIT < FSSIZE ))
|
||||
then
|
||||
if (( FSMB_FREE < FSLIMIT ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
# using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Invalid filesystem MAX for\
|
||||
$FSMOUNT - $FSLIMIT"
|
||||
$ECHO " Exceptions file value must be less\
|
||||
than or"
|
||||
$ECHO " equal to the size of the filesystem\
|
||||
measured"
|
||||
$ECHO " in 1024 bytes\n"
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Null value specified in exceptions\
|
||||
file"
|
||||
$ECHO " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
PC) # Use Filesystem %Used Method
|
||||
# Strip out the % sign if it exists
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g)
|
||||
# Test for blank and null values
|
||||
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
|
||||
then
|
||||
# Test for a valid percentage, i.e. 0-100
|
||||
if (( FSLIMIT >= 0 && FSLIMIT <= 100 ))
|
||||
then
|
||||
if (( $PC_USED > $FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Invalid percentage for $FSMOUNT -\
|
||||
$FSLIMIT"
|
||||
$ECHO " Exceptions file values must be"
|
||||
$ECHO " between 0 and 100%\n"
|
||||
fi
|
||||
else
|
||||
$ECHO "\nERROR: Null value specified in exceptions\
|
||||
file"
|
||||
$ECHO " for the $FSMOUNT mount point.\n"
|
||||
fi
|
||||
;;
|
||||
N) # Method Not Specified - Use Script Defaults
|
||||
if (( FSSIZE >= FSTRIGGER ))
|
||||
then # This is a "large" filesystem
|
||||
if (( FSMB_FREE < MIN_MB_FREE ))
|
||||
then
|
||||
return 1 # Found out of limit
|
||||
# using MB Free method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
else # This is a standard filesystem
|
||||
PC_USED=$($ECHO $PC_USED | sed s/\%//g) # Remove %
|
||||
FSLIMIT=$($ECHO $FSLIMIT | sed s/\%//g) # Remove %
|
||||
if (( PC_USED > FSLIMIT ))
|
||||
then
|
||||
return 2 # Found exceeded by % Used method
|
||||
else
|
||||
return 3 # Found OK
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
|
||||
|
||||
return 4 # Not found in $EXCEPTIONS file
|
||||
}
|
||||
|
||||
10
chapter17/function_display_output
Executable file
10
chapter17/function_display_output
Executable file
@@ -0,0 +1,10 @@
|
||||
function display_output
|
||||
{
|
||||
if [[ -s $OUTFILE ]]
|
||||
then
|
||||
$ECHO "\nFull Filesystem(s) on $THISHOST\n"
|
||||
cat $OUTFILE
|
||||
print
|
||||
fi
|
||||
}
|
||||
|
||||
11
chapter17/function_get_OS_info
Executable file
11
chapter17/function_get_OS_info
Executable file
@@ -0,0 +1,11 @@
|
||||
function get_OS_info
|
||||
{
|
||||
# For a few commands it is necessary to know the OS and its level
|
||||
# to execute the proper command syntax. This will always return
|
||||
# the OS in UPPERCASE
|
||||
|
||||
typeset -u OS # Use the UPPERCASE values for the OS variable
|
||||
OS=`uname` # Grab the Operating system, i.e. AIX, HP-UX
|
||||
print $OS # Send back the UPPERCASE value
|
||||
}
|
||||
|
||||
7
chapter17/function_load_AIX_FS_data
Executable file
7
chapter17/function_load_AIX_FS_data
Executable file
@@ -0,0 +1,7 @@
|
||||
function load_AIX_FS_data
|
||||
{
|
||||
|
||||
df -k | tail +2 | egrep -v "/dev/cd[0-9]|/proc" \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
8
chapter17/function_load_EXCEPTIONS_data
Executable file
8
chapter17/function_load_EXCEPTIONS_data
Executable file
@@ -0,0 +1,8 @@
|
||||
function load_EXCEPTIONS_data
|
||||
{
|
||||
# Ingore any line that begins with a pound sign, #
|
||||
# and omit all blank lines
|
||||
|
||||
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
|
||||
}
|
||||
|
||||
6
chapter17/function_load_FS_data
Executable file
6
chapter17/function_load_FS_data
Executable file
@@ -0,0 +1,6 @@
|
||||
function load_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v '/dev/cd[0-9] | /proc' \
|
||||
| awk '{print $1, $2, $3, $4, $7}' > $WORKFILE
|
||||
}
|
||||
|
||||
7
chapter17/function_load_HP_UX_FS_data
Executable file
7
chapter17/function_load_HP_UX_FS_data
Executable file
@@ -0,0 +1,7 @@
|
||||
function load_HP_UX_FS_data
|
||||
{
|
||||
|
||||
bdf | tail +2 | egrep -v "/cdrom" \
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
7
chapter17/function_load_LINUX_FS_data
Executable file
7
chapter17/function_load_LINUX_FS_data
Executable file
@@ -0,0 +1,7 @@
|
||||
function load_LINUX_FS_data
|
||||
{
|
||||
|
||||
df -k | tail -n +2 | egrep -v "/cdrom"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
6
chapter17/function_load_OpenBSD_FS_data
Executable file
6
chapter17/function_load_OpenBSD_FS_data
Executable file
@@ -0,0 +1,6 @@
|
||||
function load_OpenBSD_FS_data
|
||||
{
|
||||
df -k | tail +2 | egrep -v "/mnt/cdrom"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
7
chapter17/function_load_Solaris_FS_data
Executable file
7
chapter17/function_load_Solaris_FS_data
Executable file
@@ -0,0 +1,7 @@
|
||||
function load_Solaris_FS_data
|
||||
{
|
||||
|
||||
df -k | tail +2 | egrep -v "/dev/fd|/etc/mnttab|/proc"\
|
||||
| awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user