Disk Space Monitor

I used to have a script copied from UNIX Hints and Hacks for monitoring disk space but that one didn’t work on my box so I deleted it.  I finally got around to finding a better one.  It was originally copied from ‘NixCraft but I modified it heavily so it’s a bit more user friendly and doesn’t break on long device names:

    #!/bin/sh
    # Shell script to monitor or watch the disk space
    # It will send an email to $ADMIN, if the (free avilable) percentage
    # of space is >= 90%
    # -------------------------------------------------------------------------
    # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
    # This script is licensed under GNU GPL version 2.0 or above
    # -------------------------------------------------------------------------
    # This script is part of nixCraft shell script collection (NSSC)
    # Visit http://bash.cyberciti.biz/ for more information.
    # ----------------------------------------------------------------------
    # Linux shell script to watch disk space (should work on other UNIX oses )
    # SEE URL: http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
    # set admin email so that you can get email
    ADMIN="operator@lakemasoniccenter.org"
    # set alert level 90% is default
    ALERT=90
    df -PH | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 " " $6 }' | while read output;
    do
            #echo $output
            usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
            partition=$(echo $output | awk '{ print $2 " mounted on " $3}' )
            if [ $usep -ge $ALERT ]; then
                    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
                    mail -s "Alert: Almost out of disk space $partition" $ADMIN
            fi
    done
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: