Shell script to monitor or watch the disk space

Shell script to monitor or watch the disk space

#!/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%
# ————————————————————————-
# Linux shell script to watch disk space (should work on other UNIX oses )
# SEE URL: http://www.indiangnu.org
# set admin email so that you can get email
ADMIN=”ravi@indiangnu.org”
# set alert level 90% is default
ALERT=90
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)” |
mail -s “Alert: Almost out of disk space $usep” $ADMIN
fi
done

=================

Thank You,

Ravi Bhure

Similar Posts:

Be Sociable, Share!

3 Replies to “Shell script to monitor or watch the disk space”

  1. Good shell script. But it has got some bugs. Can we expect a Bug-Free script ?

    bigworm32.nino:$ ./diskspace
    ./diskspace: line 18: syntax error near unexpected token `(‘
    ./diskspace: line 18: `echo “Running out of space \”$partition ($usep%)\” on $(hostname) as on $(date)” |’

  2. Hi!! Please check now there was syntax error at line no 13
    This script will work for you..
    ** If you don’t have mail command to send mails please refer the post related to pyhton

    #!/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%
    # ————————————————————————-
    # Linux shell script to watch disk space (should work on other UNIX oses )
    # SEE URL: http://www.indiangnu.org
    # set admin email so that you can get email
    ADMIN=”ravi@indiangnu.org”
    # set alert level 90% is default
    ALERT=90
    #########
    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)”
    echo “Running out of space ‘$partition ($usep%)’ on $(hostname) as on $(date)” | mail -s “Alert: Almost out of disk space $usep” $ADMIN
    fi
    done

Leave a Reply

Your email address will not be published. Required fields are marked *