script to alert about filesystem

Taking care of your Linux box.

script to alert about filesystem

Postby ghulam yaseen » Tue May 04, 2010 2:33 pm

Dear All,

I am looking for a script by which i get email alert if disk space goes above 80%, while this script should not email unless filesystem reaches 81% and then next email after 82% and on and on.

Regards,
Ghulam Yaseen
ghulam yaseen
Naik
 
Posts: 68
Joined: Thu Aug 07, 2008 6:09 pm
Location: karachi

Postby Shahbaz_Aslam » Sat May 15, 2010 12:57 pm

use Nagios
a complete solution for these type of needs.
Shahbaz_Aslam
Lance Naik
 
Posts: 23
Joined: Fri Sep 01, 2006 12:16 am
AOL: friendshaz

Postby azfar » Sat May 15, 2010 6:18 pm

Code: Select all

#!/bin/sh
subject="Disk Usage Warning"
file=`pwd`/usage
use=`cat $file`
email="root"
mbody=/tmp/body
usage=`df -h /dev/sda1 | awk 'NR==1{next}{ if ($5 > '$use') print $6 " is at " $5;}'`

if [ -n "$usage" ]; then
echo "$usage" > $mbody
#mail -s "$subject" "$email" < $mbody
echo $usage
echo $use + 1 |bc > $file
fi
Azfar Hashmi
Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Postby azfar » Sat May 15, 2010 7:49 pm

updated.

Code: Select all

#!/bin/sh
subject="Disk Usage Warning"
file=`pwd`/usage
use=`cat $file`
email="root"
mbody=/tmp/body
usage=`df -h /dev/sda1 | awk 'NR==1{next}{ if ($5 > '$use') print $6 " is at " $5;}'`
usage1=`df -h /dev/sda1 | awk 'NR==1{next}{ if ($5 < 81) print $5;}' | cut -b 1-2`


if [ -n "$usage" ]; then
echo "$usage" > $mbody
mail -s "$subject" "$email" < $mbody
echo $usage
echo $use + 1 |bc > $file
fi
if [ -n "usage1" ]; then
echo 80 > $file
fi
Last edited by azfar on Sat May 15, 2010 8:05 pm, edited 1 time in total.
Azfar Hashmi

Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Postby azfar » Sat May 15, 2010 7:58 pm

you have to put your threshold (80) in a file "usage".

When your usage reached 81% it will email you and only alert you next time when the usage reached to 82% and so on. It will reset the threshold to 80 when disk reduced below 81%.
Azfar Hashmi

Email : azfarhashmi@hotmail.com
azfar
Captain
 
Posts: 598
Joined: Tue Mar 23, 2004 1:16 am
WLM: azfarhashmi@hotmail.com
Yahoo Messenger: azfarhusain@yahoo.com
Location: Karachi

Postby ghulam yaseen » Tue May 18, 2010 12:18 pm

nice!
ghulam yaseen
Naik
 
Posts: 68
Joined: Thu Aug 07, 2008 6:09 pm
Location: karachi


Return to “%s” Administration

Who is online

Users browsing this forum: No registered users and 1 guest

cron