Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



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

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-12-2010
Registered User
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
File System exceed Alert Script!

Hello Allz,

Please review my following script. The purpose of the script is to check the file system every 5 minutes & if any file systems is exceed from 90% then raise an email alert only 1 time.

But the following script not functioning properly, mostly send an email that contain only Date, even if any file system exceed from ALERT=90%



Code:
###########################################
ALERT="90"
ALERT1="85"
DFH="/tmp/dfout"
DFM="/tmp/dfmail"
CHK="/tmp/hdsize-chk"
###########################################
EMAIL="Email ID"
SUBJECT="WARNING! Disk Usage of $(uname -n)"
MAILPROG="/bin/mail"
###########################################

rm -f $DFM
clear
echo
echo `date` | tee $DFM
echo | tee -a $DFM
df -h > $DFH
cat $DFH | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
  #echo $output
  USEP=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  FS=$(echo $output | awk '{ print $2 }' )
  if [ $USEP -gt $ALERT ]
  then
  echo "Running out of space \"$FS - ($USEP%)\"" | tee -a $DFM
  fi
done
if test -f $CHK
then
echo "Not Sending an Email"
exit
else
echo Sending an Email
$MAILPROG -s "$SUBJECT" "$EMAIL" < $DFM
echo Creating Tmp File
touch $CHK
fi
if [ $USEP -lt $ALERT1 ]
then
echo Removing Tmp File
rm -f $CHK
 
fi


Last edited by vgersh99; 03-12-2010 at 07:40 AM.. Reason: code tags, please!
Sponsored Links
  #2  
Old 03-12-2010
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 802
Thanks: 9
Thanked 34 Times in 33 Posts
which box do you have?
can you post the sample output of "df -h" from your machine?
  #3  
Old 03-12-2010
Registered User
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

I am using Redhat Linux 5.0


Code:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1  20G  8.2G 11G   44%   /
/dev/sda3  40G  33G 5.2G   87%   /d01
/dev/sdb  148G  113G 28G   81%   /san
/dev/sdc   50G  9.0G 38G   20%   /san01
/dev/sdd  403G  300G 82G   79%   /san00


Last edited by pludi; 03-15-2010 at 05:16 AM.. Reason: code tags, please...
  #4  
Old 03-12-2010
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 5,591
Thanks: 2
Thanked 68 Times in 65 Posts
This questions is a frequently asked question, check this post:

Disk Space Monitoring Script

You can easily search the forums using our internal Google search engine or our advanced internal search engine. You can also search our huge UNIX and Linux database by user generated tags or search the database for unanswered questions and provide an answer.

Thank you.
  #5  
Old 03-12-2010
Registered User
 

Join Date: Mar 2008
Posts: 2,204
Thanks: 5
Thanked 40 Times in 39 Posts
I'd start by putting a shebang line on the first line of your script so we can be sure which shell will be used whether or not it is run from cron.

Something like:

Code:
#!/bin/bash


When the script has run, what is in the file pointed to by $DFM ?

Also try checking that $DFM has been passed into the while loop:

Code:
do
  echo $DFM

  #6  
Old 03-12-2010
Registered User
 

Join Date: Mar 2008
Location: Surrounded...
Posts: 336
Thanks: 1
Thanked 20 Times in 20 Posts
squirreled away in a .file:


Code:
   function space 
   {
      #  This function does a quick read and display of the File System consumption... 
      #     only it formats it in a more human-readable way... 
      df -kP |head -1 |while read a b c d e f g                            \
         ;do printf "\n %-35.35s %12.12s %12.12s %12.12s   spent   %-s \n" \
         $a                                                                \
         GBs                                                               \
         "${c} (GBs)"                                                      \
         "${d} (GBs)"                                                      \
         $f                                                                \
         ;done                                                             \
         && df -kP |egrep -v "Program|Filesystem"                          \
            |while read a b c d e f g                                      \
            ;do printf " %-35.35s %12.2f %12.2f %12.2f   %5.5s   %-s \n"   \
            $a                                                             \
            $(echo "(${b}/1048576*100000)/100000" |bc -l 2>/dev/null )     \
            $(echo "(${c}/1048576*100000)/100000" |bc -l 2>/dev/null )     \
            $(echo "(${d}/1048576*100000)/100000" |bc -l 2>/dev/null )     \
            $e                                                             \
            $f                                                             \
            ;done                                                          \
         && echo 
   }

Added to whatever script your cron job is calling...

Code:
   function LOG 
   {
      if [ -n "${MY_LOG}" -a -f "${MY_LOG}" ] 
      then 
         print "$@" >>"${MY_LOG}" 
      fi 
   }

   LOG   "\n$(date) : ${0##*/} begin " 

   #  Try to source the appropriate library for space() function... 
   if    [[ ! -r ~/.sh_snippets ]] || [[ ! -x ~/.sh_snippets ]] 
   then 
      LOG "\n\t${0##*/}: Could not access library file: ~/.sh_snippets " 
      LOG "\n$(date) : ${0##*/} complete " 
      exit 1 
   # initialize other stuff... 
   elif  [[ ! -f "...blah..." ]] 
   then 
      LOG "\n\t${0##*/}: required environment...sorry. " 
      LOG "\n$(date) : ${0##*/} complete " 
      exit 1 
   else 
   #  Use the source, young padewan... 
      . ~/.sh_snippets           >/dev/null 2>&1 
   fi 

   #  Checking Filesystem usage...notify if anything in excess of 93%... 
   #  If there's a positive hit on the over 93% crowd, then send an e-mail... 
   if [[ ! -z $(space |egrep "[ 1][09][3-9]\% |100\% ") ]] 
#   if [[ ! -z $(space |egrep "[ 1][09][5-9]\% |100\% ") ]] 
   then 
      space |egrep "^F|[ 1][09][3-9]\% |100\% " |mailx -s "$(uname -n) - Filesystem space warning... $(date )" fu_schnickens@bar.com 
      LOG   "\n\t${0##*/} : Filesystem space warning generated...! " 
   else 
      LOG   "\n\t${0##*/} : Filesystem space okay..." 
   fi

  #7  
Old 03-15-2010
Registered User
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Plz reviewmy script & correct it.

Curleb thanks for ur script but i dont want to use any one script.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to send an alert if a file is present in a directory for 10 min madfox Shell Programming and Scripting 5 12-30-2009 09:43 AM
File system backup alert a1_win Shell Programming and Scripting 0 05-13-2009 09:54 AM
Help? Any method to send system alert email? ITJacky UNIX for Dummies Questions & Answers 1 06-03-2006 07:29 PM
Alert system owange_county Post Here to Contact Site Administrators and Moderators 2 10-12-2005 08:31 PM
Shel Script doesn't work from Exceed dnkansah Shell Programming and Scripting 11 08-16-2004 05:22 AM



All times are GMT -4. The time now is 07:51 AM.