Mar
25
Posted on 25-03-2008
Filed Under (Shell scripting) by Ravi Bhure

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) Comments    Read More   

Comments

Ashish Gangani on 31 March, 2008 at 5:58 pm #

It is usefull for Servers.
Thanks…………….


Ravi on 1 April, 2008 at 9:32 am #

Thanks Ashish,
You find more useful scripts for servers in future.


Post a Comment
Name:
Email:
Website:
Comments:


www.flickr.com
arunbagul's photos More of arunbagul's photos
Get Adobe Flash player
-->