Shell script to monitor current disk space and getting alert on thresh hold level | MyLiteratureTechLife.COM

Shell script to monitor current disk space and getting alert on thresh hold level

December 13th, 2011 0 Comments






















Yesterday I wrote a post when I found a script to monitor disk space in a server and getting alert on thresh hold level. However that script just send a notification when disk space is on thresh hold, but I wanted to get disk usage on daily basis therefore I made some modifications in script.

#!/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
#--------------------------------------------------------------------------
# Modified by http://WWW.MyliteratureTechLife.com
# Added code to send an email with current usage
# ----------------------------------------------------------------------
# Linux shell script to watch disk space (should work on other UNIX oses )
# SEE URL: http://www.myliteraturetechlife.com/shell-script-to-monitor-current-disk-space-and-getting-alert-on-thresh-hold-level/
# 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
	 else
	 echo "Still enough space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Still enough disk space $usep%" $ADMIN
  fi
done

Related posts:

  1. Monitoring your disk space with shell script
  2. PHP script to test MySQL database Connection
  3. Monitor your server with Munin
  4. The disk is offline because of policy set by Administrator
  5. Log rotation in plesk 8.x
  6. How to increase Qmail sending limit
  7. Securing Kloxo lxadmin with iptables firewall
  8. How to transfer a Linux image from VirtualBox to Xen
 

If You Like This Post, Share it With Your Friends & Peers

Digg
stumbleupon
Delicious
facebook
twitter
reddit
rss feed bookmar
 

No Comment to “Shell script to monitor current disk space and getting alert on thresh hold level”

  1. No Comment yet. Be the first to comment...

Leave your comment here:

*

Alexa Rank