Tuesday, June 23, 2015

Tools to get mail alert notification if disk space is full Linux

Is there any tools to get mail alert notification if disk space is full?

 Tools

You can use Nagios tool and set disk alert as per your requirement. Nagios is a centralised monitoring service. If you need that only for 1 server you don't need nagios.
 

A single script could help you or use munin or monit toolsI guess it could help you too. So, below tools can be used.

  • Nagios
  • Munin
  • Monit

 Script to monitor

Of course you need to configure your server to allow mail sending.

#!/bin/bash
a=`df -h | sed '1d' | awk '$5 > 30 {print $5}' | tr -d %`
if [[ $a -ge 95 ]]

then
echo "running out of disk space"
mail -s "diskalert: $a%"
yourmail@address.com
fi


OR

#! /bin/bash
mail='yourmail@address.com'
reg='^[0-9]+$'
result=`df|awk '{print $1,$5}'|tail -n+2|tr -d '%'`

for i in $result; do
if [[ $i =~ $reg ]]; then
[[ $i -gt 90 ]] && (echo $result|mail -s "Disk alert" $mail ) && break
fi
done


No comments:

Post a Comment