Mini Shell
#!/bin/bash
# This script shows the available disk space for the month on a given shared server
# written by Erik S. ext 834 e@inmotion.net
#lets set some important variables
SESSIONID=`date +%s`
MONTH=`date '+%b'`
FULLMONTH=`date '+%B'`
DAY=`date '+%d'`
HOUR=`date '+%H'`
TODAY=$DAY
OURSERVER=`hostname -s`
if [ -f /opt/sharedrads/radsfunctions.sh ]; then
source /opt/sharedrads/radsfunctions.sh
else
source /opt/dedrads/radsfunctions.sh
fi
#if we got a flag passed, skip the fanciness
if [ -z "$1" ]; then
if [ "$RADSCOLORS" == "off" ];
then
radsbanner-nocolor
else
radsbanner
fi
echo " SHOWING DAILY AVAILABLE DISK SPACE TREND IN MEGABYTES(MB) FOR THIS MONTH" ; echo
fi
cat /var/log/sa/rads/diskavail/* | awk '
BEGIN { printf "%-7s %-20s %-20s %-30s\n", "DAY", "PREVIOUS", "CURRENT", "CHANGE +/-"; }
{
if (NR==1) { previous = $2; }
current=$2;
rateofchange = current - previous;
printf "%-7s %-20s %-20s %-30s\n",NR,(previous/1024),(current/1024),(rateofchange/1024);
#printf "%s ",(rateofchange/1024)/1024;
previous = current ;
}
END{ printf "\n"; }
' | head -`expr $DAY + 1` > /tmp/.$SESSIONID
AVGDAILY=`cat /tmp/.$SESSIONID | grep -v CHANGE | awk '{ SUM += $4 } END { print SUM/$1 }'`
if [ "$1" == "--avg" ]; then
echo "$OURSERVER $AVGDAILY MB/day (average)"
exit 0
else
cat /tmp/.$SESSIONID
echo
echo " The average disk trend for $FULLMONTH is: $AVGDAILY MB/day"
echo
fi
rm -f /tmp/.$SESSIONID #cleanup
Zerion Mini Shell 1.0