#!/bin/bash
################################################################
# Constants
readonly THIS_JOB=${0##*/}
readonly ARGS_NBR=0
readonly ALERT=80
# declare -x mrecipients="p.doulgeridis@dei.com.gr"
# declare -x msender="K.Athanasopoulos@dei.com.gr"
# declare -x mtitle="DISK USAGE NOTIFICATION"
# declare -x ccrecipients="i.niarchos@dei.com.gr,p.doulgeridis@dei.com.gr"
# declare -x mrecipients="p.doulgeridis@dei.com.gr"
# declare -x msender="K.Athanasopoulos@dei.com.gr"
# declare -x mtitle="DISK USAGE"
# declare -x ccrecipients="p.doulgeridis@dei.com.gr"
declare -x mrecipients="p.doulgeridis@dei.com.gr,K.Athanasopoulos@dei.com.gr"
declare -x msender="tee@dei.com.gr"
declare -x mtitle="DISKSPACE_ERROR"
declare -x ccrecipients="p.doulgeridis@dei.com.gr,a.pavlidis@dei.com.gr,i.niarchos@dei.com.gr"
function usage(){
echo " Script : $THIS_JOB called as :"
echo " $THIS_JOB <DATE>"
echo " Date must be in the format YYMMDD "
echo " Script will search for the lines of FILTER (2 fields) and "
echo " find matches in FILE_INPUT, then email."
echo
}
function chk_abnd_silent()
{
local abnd
abnd=$1
# date
if [ $abnd -ne 0 ]; then
echo "Failed with status " $abnd; echo
#rm +++++++++++++
exit $abnd
#return $abnd
# else
# echo "Done"; echo
fi
}
#
# Check arguments
function chk_args()
{
local nbr_args=$1
if [ $nbr_args -ne $ARGS_NBR ]; then
echo "Wrong number of parameters = " $nbr_args
usage
exit 69
else
#echo "User has supplied the correct number of arguments"
return 0
fi
}
#################################################################
# Script start.
# echo $THIS_JOB " start time at `date` "; echo
# echo "-"
# Check number of arguments
#chk_args $#
# Run continuously
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
#echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | mailx -S smtp=holhub -r $msender -s $mtitle -c $ccrecipients -v $mrecipients
#sleep 2
fi
done
#echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" | mailx -S smtp=holhub -r $msender -s $mtitle -c $ccrecipients -v $mrecipients