Alert mail for low disk space

Alert mail for low disk space

Few months ago I wrote a script that mail to admin for low disk space Shell script to monitor or watch the disk space but now here we improved the script in few better steps.

#!/bin/bash

# Shell script to monitor or watch the low-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
# set alert level 90% is default

PATHS=”/”

AWK=/bin/awk

DU=”/usr/bin/du -ks”

GREP=/bin/grep

DF=”/bin/df -k”

TR=/usr/bin/tr

SED=/bin/sed

CAT=/bin/cat

MAILFILE=/tmp/mailviews$$

MAILER=/bin/mail

mailto=”ravi@indianGNU.org”

for path in $PATHS

do

DISK_AVAIL=`$DF $path | $GREP -v “Filesystem” | $AWK ‘{print $5}’|$SED ‘s/%//g’`

if [ $DISK_AVAIL -gt 90 ];then

echo “Please clean up your stuff \n\n” > $MAILFILE

$CAT $MAILFILE | $MAILER -s “Clean up stuff” $mailto

fi

done

Thanks

RAvi

Similar Posts:

Be Sociable, Share!

2 Replies to “Alert mail for low disk space”

Leave a Reply

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