File System exceed Alert Script!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File System exceed Alert Script!
# 1  
Old 03-12-2010
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 08:40 AM.. Reason: code tags, please!
# 2  
Old 03-12-2010
which box do you have?
can you post the sample output of "df -h" from your machine?
# 3  
Old 03-12-2010
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 07:16 AM.. Reason: code tags, please...
# 4  
Old 03-12-2010
This questions is a frequently asked question, check this post:

https://www.unix.com/shell-programmin...#post302133430

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
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
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
Plz reviewmy script & correct it.

Curleb thanks for ur script but i dont want to use any one script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to monitor diskspace of /home/ not to exceed 80%

I want to monitor the diskspace of the /home/ directory NOT to exceed 80%. I want a script_file.sh for this. I am trying "df -h" command and I am stuck unable to extract the percentage. 1. HOW TO extract the percentage (I believe 5th column)? 2. IF we were able to extract the column,... (8 Replies)
Discussion started by: Shreyas N
8 Replies

2. Shell Programming and Scripting

shell script to alert if a file has been modified

Hi , I want a script who will send alert the moment someone edit any file in a directory in LINUX. Can some one throw some light on this please.!! (4 Replies)
Discussion started by: d8011
4 Replies

3. Shell Programming and Scripting

Looking for shell script to monitor CPU utilization and send mail once exceed 75%

Dear Group, I'm look for shell script to Monitor CPU usage and send mail once it exceed 75% I'm running Suse10.4. (3 Replies)
Discussion started by: clfever
3 Replies

4. Shell Programming and Scripting

Script to Alert a file and sends an email

Hello All, I need a script which alerts me when a files arrive in a directory. I don't need every file. but i need some specific pattern file. And i need to get automatic email gettin as an alert For Example: /a/b/c/ : directory format of file should take regualr expression or manually... (2 Replies)
Discussion started by: krux_rap
2 Replies

5. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

6. Infrastructure Monitoring

Monitoring and Alert System

hi, i serarch monitoring and alert system. when HDD and services are down. Send email and sms alert to me and help desk. but i don't find any program. Can you help me ? Thanks. (1 Reply)
Discussion started by: oulutas
1 Replies

7. Shell Programming and Scripting

File system backup alert

Hi All, OS: AIX 5.3 64 bits Could anyone please share unix File system backup alert shell script which sends an alert message upon failure.. Thanks for your time! Regards, (0 Replies)
Discussion started by: a1_win
0 Replies

8. Post Here to Contact Site Administrators and Moderators

Alert system

Do you have an alert system? meaning when your question has been answer, could be u guys send an email, informing the question has been answer, of someone did post a reply? Thanks (2 Replies)
Discussion started by: owange_county
2 Replies

9. Shell Programming and Scripting

Shel Script doesn't work from Exceed

Hi, I am using this script to load up my Oracle Databases, but when I log in through Exceed, it hangs. Can anyone tell me what else I need to add to make this work?? Details ****************************************************************************************************... (11 Replies)
Discussion started by: dnkansah
11 Replies

10. Programming

Max file size can't exceed 2 GB

We have Sun OS 5.9 we are doing a backup process (ProC program) that uses the function... fprintf(fp,"%s;%s;%s;%s;%s;%ld;%ld;%ld;%ld;%s;%s;%s;%d;%s;%s;%s;%ld;%s;%s;%s;%ld;%ld;%s;%ld;%s;%ld;%s;%s;%c%c",x_contrno, x_subno, x_b_subno,x_transdate,x_last_traffic_date,BillAmt_s, x_billamount_int,... (10 Replies)
Discussion started by: atiato
10 Replies
Login or Register to Ask a Question