The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Disk Space Monitoring Script sriram003 Shell Programming and Scripting 8 08-23-2007 08:00 AM
need help with disk check script xramm Shell Programming and Scripting 4 07-15-2007 01:34 PM
Disk space script asadlone Shell Programming and Scripting 8 06-03-2007 12:32 PM
Frustrating Disk space script vivsiv Shell Programming and Scripting 4 06-05-2006 04:53 PM
disk space script debug - posted before bryan Shell Programming and Scripting 3 04-28-2005 04:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2008
Registered User
 

Join Date: May 2008
Posts: 2
Please help - disk space check script

I have a disk space check script that uses an exceptions file, the only issue with the script is that it does not work with values higher than the FSMAX=85 value. I have a file system that is at 92% and it doesn't change, so I would like to add it to the exceptions file. The exceptions file format is

/usr 92%

Below is the script, anyone know what I'm doing wrong?

========================================================

#!/usr/bin/ksh
#
#
#
##### 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="/operator" # Local 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, #
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
}

###################################

function check_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 OUT OF LIMITS - 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

df -k | tail +2 | egrep -v "/dev/vx/dmp|/dev/vx/rdmp|/proc|/mnttab|/dev/fd|/var/run|sapdata" \
| 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 [[ -s $EXCEPTIONS ]] # Do we have a non-empty file?
then

# 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 mounted 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 mounted 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 mounted 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

========================================================

Last edited by maddhadder71; 05-08-2008 at 05:31 AM. Reason: Missing a part of the script
Reply With Quote
Google The UNIX and Linux Forums
Forum Sponsor
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0