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:
- Alert mail for low disk space
- Script for checking CPULOAD and send email to admin
- Shell script to monitor running services such as web/http, ssh, mail etc.
- How to convert shell script in to binary executable
- Nagios daily and weekly Reporting and log parsing
- How to read MBR (Master Boot Record)
- Capturing a UNIX terminal session!
3 Replies to “Shell script to monitor or watch the disk space”
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)â |’
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