The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-26-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Here is a script we use on our HP-UX servers, it runs in cron wvery 30mins and would immediately send out an email.

There are actually 2 warning levels, Warning and EMERGENCY.

Code:
 n[1]=1; fs[1]=/; limit1[1]=70; limit2[1]=80;

this line sends a warning at 70% and EMERGENCY at 80% for root.


Code:

#!/usr/bin/ksh

# Setup the date variables
FullDate=`date`
Date=`date +%m%d`

# Setup the other variables
ProgName=checkfilesystem
SCRIPTDIR=/local/bin/
LOG=/syslog/filecheck.log
TMP=/tmp/${ProgName}.$$
TMP2=/tmp/${ProgName}.${$}.2
MAILSUPPORT="someemail@email.com"

# Setup the Node name
host=`hostname`

#Here are the filesystems which are checked

  n[1]=1; fs[1]=/; limit1[1]=70; limit2[1]=80;
  n[2]=2; fs[2]=/var; limit1[2]=80; limit2[2]=90;
  n[3]=3; fs[3]=/usr; limit1[3]=80; limit2[3]=95;
  n[4]=4; fs[4]=/tmp; limit1[4]=50; limit2[4]=90;
  n[5]=5; fs[5]=/home; limit1[5]=70; limit2[5]=90;
  n[6]=6; fs[6]=/stand; limit1[6]=60; limit2[6]=80;
  n[7]=7; fs[7]=/opt; limit1[7]=80; limit2[7]=90;


  #...End of locally modifyable section

exec > $LOG 2>&1


  for x in ${n[*]}
  do
  xfs=${fs[$x]}
  l1=${limit1[$x]}
  l2=${limit2[$x]}
  pctfull=`df -k $xfs|grep allocation |awk '{print $1}'|tr -d '%'`
  if (( $pctfull > $l2 )); then
echo "EMERGENCE EMERGENCY EMERGENCY"
echo "$xfs=$pctfull on $host"
echo "Check filesystem and solve the problem"
echo

else
  if (( $pctfull >= $l1)); then

echo "Warning $xfs=$pctfull on $host"
echo "Please check the filesystem"
echo
fi
fi
done
        if [[ -s $LOG && -f $LOG ]]; then
        mailx -s "Filesystem Problem on $host " $MAILSUPPORT < $LOG
        fi