Jan
02
Posted on 02-01-2008
Filed Under (Shell scripting) by Ravi Bhure

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

Comments

Bigworm32 on 14 January, 2008 at 10:38 am #

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)” |’


Arun Bagul on 15 January, 2008 at 7:01 pm #

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


[…] months ago I wrote a script that mails admin to low disk space Shell script to monitor or watch the disk space but now here we improve the script with some few […]


Post a Comment
Name:
Email:
Website:
Comments:


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