Script to send email alert when disk space usage is more than 70%

Hi,

This is a script for the linux administrators who wish to have the alerts of disk usage to be sent via email, then please run this script on your Linux box..


#!/bin/bash
usage=`df -h | awk '{print $5}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -d % -s "\n"`
devnm=`df -h | awk '{print $1}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -s "\n"`
str="============================="

if [ $usage -ge 70 ]; then
info="Disk usage for $devnm is more than 70% , Current Disk usage is $usage % "
echo -e "$str\n$info\n$str" |mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com

else
info="Disk Usage is $usage% for $devnm"
# echo -e "$str\n$info\n$str" | mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com
fi



Pages