ss_blog_claim=b824add5e9da9a45e10621e508c6a0cf

Archive for the ‘ Bash Script ’ Category

Bash Script: Disk Usage Alert

This is a working script from one of our production server. Basically this will sent an email when disk usage is in critical level.

code>#!/bin/
LIMIT=”96|97|98|99|100″
CHECK=$(df -h | awk ‘{print $5}’ | awk -F % ‘{print $1}’ | uniq | egrep -i $LIMIT)

if [[ -n "$CHECK" ]]
then
echo “=======================================================
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
=======================================================
`df -h`
=======================================================
WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
=======================================================” | mail -s “Disk Usage on $HOSTNAME” email@yourdomain.com
else
echo Good;
fi

This will generate a neat formatted email similar to this:

Popularity: 15% [?]

This is a simple that will check for the server load average then email you a report.

#!/bin/

loadaverage=$( cut -d’ ‘ -f2 /proc/loadavg )
email_alert=”email@yourdomain.com”

if [ $loadaverage -gt "5" ] ; then
echo “The server load for the past 5 minutes is $loadaverage” | mail -s “ from $HOSTNAME” $email_alert ;

fi

This script will send an email if the load average is greater than 5.

Popularity: 14% [?]