Monday, February 2, 2009

Check Available Disk Space and Notify

Here's some handy bash script to notfiy support when we are running low on disk space.


#!/bin/bash
#
# Description:Checks the available space for the disk mounted as / (root)
# If disk space is less than 10GB it will send out a notification
#

# Send emails to these people
EMAILID=support@mydomain.com

# Min Free Space
MINSPACE=10485760

# Get the space available
FREESPACE=`df / | awk '{ if( NR == 2) print $4 }'`

# Send email if required
if [ $FREESPACE -le $MINSPACE ];
then
logger "Warning: Root Drive Running Out Of Disk Space [${FREESPACE}KB]"
mail -s 'My Favourite Production Server Disk Space' ${EMAILID} << EOF
My Favourite Production server root drive is running out of disk space. Current free space is ${FREESPACE} KB @ $(date)
EOF
fi

0 comments: