6
Apr
2009
Shell Script To Monitor UNIX / Linux Server Disk Space
By admin. Posted in Linux Shell Script
6 Comments » | Share |
Shell script to monitor or watch the disk space and send an email alert if the (free avilable) percentage of space is >= 90%
[shell]#!/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="me@somewher.com"
# 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[/shell]






May 3rd, 2009 at 4:06 pm
Hi, nice post. I have been pondering this issue,so thanks for posting. I will definitely be subscribing to your blog.
May 4th, 2009 at 6:31 am
Thanxs,
you can try subscribing to email feature right side on of his page..
cos there is some issues with post rss feature… will fix it soon..
May 5th, 2009 at 4:51 am
You have inspired me. Thank you very much. Good luck with your site
May 5th, 2009 at 5:18 am
Thank you for your appreciation
May 5th, 2009 at 7:59 am
thanks !! very helpful post!
May 5th, 2009 at 9:33 am
what if your both partitions will run out of space? you will receive 2 mails. if you have more partitions, then you will receive more mails. how you do to receive all messages in one mail?