Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Simple script to Alert Over Disk Usage  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

lijeshk

  • Guest
Simple script to Alert Over Disk Usage
« on: November 01, 2013, 08:41:16 am »

This script will be helpful, If you need to be alerted when ever the disk usage on your server goes beyond certain limit.

#!/bin/sh

ADMIN="me@somewher.com" # Set your Mail ID here, to which you need to get the alert Mail
# Set alert on disk usage beyond  90%
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
------

Save and install script as cronjob as per the requirement!

 :)