#!/bin/ksh
################################################################################
## Program name : checkfs
## Purpose 	    : Checks all filesystems and alert user via mail and GSM SMS
##              : Alert if greater than 89% and send action greater than 94%
##              : Send msg only once as percentage state change 
## Author	    : Hannes Visagie
## Date written : 1999-02-21 
################################################################################

ls -lg "$1" | grep -v "^d" | awk '{sum += $4} END {print sum}'

df -k | while read LINE
do
  NAME=`echo $LINE | cut -d' ' -f6`
  PUSE=`echo $LINE | cut -d' ' -f5 | cut -d'%' -f1`

  NAME1=`echo "$NAME" | cut -d'/' -f2`
  [ "$NAME" = "Mounted" ]  && continue
  [ "$NAME" = "/dev/fd" ]  && continue
  [ "$NAME" = "/proc" ]  && continue
  [ "$NAME1" = "cdrom" ]  && continue

  #--- Remove all flags if less than 90% used ---
  if [ $PUSE -lt 90 ]
  then
    rm "/var/log/full_$NAME1"*  > /dev/null 2>&1
    continue
  fi
  PUSE2=`expr $PUSE + 2`
  rm "/var/log/full_$NAME1.$PUSE2"  > /dev/null 2>&1

  #--- Send Message once only ---
  [ -r "/var/log/full_$NAME1.$PUSE" ] && continue

  if [ $PUSE -ge "95" ] 
  then
    MSG=`uname -n`" ACTION $NAME is $PUSE% full at "`date '+%Y/%m/%d %H:%M:%S`
  else
    MSG=`uname -n`" warning $NAME is $PUSE% full at "`date '+%Y/%m/%d %H:%M:%S`
  fi

  > "/var/log/full_$NAME1.$PUSE"
  echo "$MSG"
  /usr/scripts/sms hv "$MSG"
  CC="support@mibco.org.za"
  echo "$MSG" | mailx -s "$MSG" -c "$CC" hvisagie@mibco.org.za
done

