This is a very useful and small script that I created quiet some time back when I was creating custom monitoring plugins for one my my clients.
Still I use this script to perform Disk Size Monitoring at many places that I am monitoring.
For this script to work properly, a small linux command line utility known as "mutt" needs to be installed. It is a very handy command line e-mail client. Normally this comes by default with linux, but just in case this is not present, simply use the native package manager (yum for redhat/centos/fedora and apt-get for debian/ubuntu) to install this utility.
Now for the script. It is a bit messed up.
[root@crystalnetworks.org home]# cat disksize.sh
#!/bin/bash
#
# Author : Mudasir Mirza
#Un-comment the following line to run the script in debug mode
#set -x
# Absolute path to CSV file that will be generated by script
OUTPUT="/tmp/size.csv"
rm -f $OUTPUT
NUM_COL=`df -h | head -n1 | awk '{ print NF }'`
for (( i=1; i<=$NUM_COL; i++ ))
do
COM[$i]=`df -h | head -n1 | awk -v "awkvar=$i" '{print $awkvar}'`
done
FLD=`echo ${COM[@]} | sed 's/\ /,/g'`
echo $FLD > $OUTPUT
P=`df -h | tail -n+2 | wc -l`
for (( i=1; i<=$P; i++ ))
do
CMD=`df -h | tail -n+2 | sed "${i}!d"`
CMDA=`echo $CMD | sed 's/\ /,/g'`
echo $CMDA >> $OUTPUT
done
echo | mutt -a $OUTPUT -s "Daily Disk Size Email" monitoring@example.com
###########################################################
# End of Scirpt