The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 11:00 AM
need help with disk check script xramm Shell Programming and Scripting 4 07-15-2007 04:34 PM
Disk space script asadlone Shell Programming and Scripting 8 06-03-2007 03:32 PM
Frustrating Disk space script vivsiv Shell Programming and Scripting 4 06-05-2006 07:53 PM
disk space script debug - posted before bryan Shell Programming and Scripting 3 04-28-2005 07:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2008
maddhadder71 maddhadder71 is offline
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 08:31 AM.. Reason: Missing a part of the script
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0