Re: How to configure one script to send mail alerts if filesystem is reaching 90% (524 Views)
Reply
Regular Advisor
senthil_kumar_2
Posts: 116
Registered: ‎03-02-2009
Message 1 of 16 (524 Views)
Accepted Solution

How to configure one script to send mail alerts if filesystem is reaching 90%

Hi All,

I have written one script and configured that in crontab for sending mail alerts if filsystem is reaching thrushold of 90%.

For example:

1)#vi /usr/local/bin/disk_full.sh

#!/bin/sh
bdf | awk 'z[split($5,z,"%")-1]>90' | mailx -r senthil.kumar@emdiesels.com -s "$HOST Filesystems > 90%" abc@yahoo.co.in


2)crontab -e

########### Send mail alerts if any filesystem reaches thrushold 90%##########
1 * * * * /usr/local/bin/disk_full.sh
##########################################################


I have written above script to check if any of the filesystes is reaching thrush hold of 90% for every one hour and send mails if any of the filesystems is reached 90%.

It is working fine.

But I have following issues.

My Issue:

I am getting blank mail alerts even if any of filesystems is not reaching 90%. Therefore I am getting one mail from for ever one hour even if there is no filesystem is reached thrush hold of 90%.

My Requirement:

I would like to receive mail alerts only if any of the file system is reaching thrush hold of 90% but not for empty (If there is no filesystems reached 90%).

How to resolve this.



Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi Senthil:

As written, regardless of any output, 'mailx' is spawned by the pipe. Hence, you unconditionally get mail regardless of the utilization threshold.

You could do:

# [ -z "$(bdf|awk 'z[split($5,z,"%")-1]>90')" ] || mailx ...

...or capture the output; test the output for emptiness and email the non-empty result.

# RESULTS=$(bdf|awk 'z[split($5,z,"%")-1]>90')
# [ -z "${RESULTS}" ] || mailx ...

Regards!

...JRF...
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again) Senthil:

By the way, you have a recently growing number of questions you have asked without any point assignment whatsoever:

http://forums.itrc.hp.com/service/forums/pageList.do?userId=WW220552&listType=unassigned&forumId=1

...JRF...

Honored Contributor
Suraj K Sankari
Posts: 1,659
Registered: ‎09-09-2008
Message 4 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi,
Got so many thread see the below
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1278423920446+28353475&...
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1336882
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1100009
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1064880
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=800551
here is the script i am using.
#!/usr/bin/ksh

PATH=/usr/bin:/usr/sbin
CONF_FILE=fs_check.conf.txt

# Source default env vars
. ${CONF_FILE}

# Count number of FS to check
i=${#FS[*]}

# Check each Filesystem
while [ "$(($i-1))" -ge "0" ]
do
let i=i-1
PCT=$(bdf ${FS[$i]} | awk '/\// {print $5}' | tr -d '%')
if [ ${PCT} -gt ${TRESH[$i]} ]
then
if [ "90" -le ${PCT} ]
then
echo "FATAL: Out of disk space for ${FS[$i]}!" | mailx -s FS_FATAL me@company.com
else
echo "WARNING: Threshold exceeded for ${FS[$i]}, it is now ${PCT}." | mailx -s FS_WARNING me@company.com
fi
fi
done
exit 0


Suraj
Regular Advisor
senthil_kumar_2
Posts: 116
Registered: ‎03-02-2009
Message 5 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi James,

I have modified the file "/usr/local/bin/disk_full.sh" as following


# more /usr/local/bin/disk_full.sh

#!/bin/bash
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90')
[ -z "${RESULTS}" ] | mailx -r senthil.kumar@emdiesels.com -s "$HOST Filesystems > 90%" senthil.kumar@emdiesels.com



Still I am getting alerts with empty message.

How to resolve.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 6 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again) Senthil:

> [ -z "${RESULTS}" ] | mailx ...

You didn't copy what I wrote and made the same mistake as you originally had. You don't want a pipe ('|') you want the logical relation ('||') as:

# [ -z "${RESULTS}" ] || mailx ...

...which says if the variable called RESULTS is not empty, run the command 'mailx'.

Regards!

...JRF...
Regular Advisor
senthil_kumar_2
Posts: 116
Registered: ‎03-02-2009
Message 7 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi James,

Still the issue is not resolved.

1)# more disk.sh
#!/bin/bash
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90')
[ -z "${RESULTS}" ] || mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com


2)# ll disk.sh

-rwxr-xr-x 1 root root 145 Jul 6 09:51 disk.sh


3)#./disk.sh

Now it is hanging , I have waited for about 10 mins. however the above script is not exectued.

So pressed "ctrl + c" , now I got follwoing output.

(Interrupt -- one more to kill letter)


Then again I pressed "ctrl + c" , now I got the prompt.

#


How to resolve.

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 8 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again):

> Now it is hanging , I have waited for about 10 mins. however the above script is not exectued.

You need to provide an some input (even if this input is "empty".

You could do:

# [ -z "${RESULTS}" ] || mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com < /dev/null

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,207
Registered: ‎03-06-2006
Message 9 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

>JRF: You need to provide an some input (even if this input is "empty".

Right. You can also echo $RESULT or read from some file:
[ -z "${RESULTS}" ] || echo "$RESULT" | mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 10 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Shalom,

I like the concept for detecting the file systems above 90%. Note that if you have openview ITO, you can get this functionality without a script.

You might try putting your output to a file and using http://hpux.ws/mailfile2 to email the output as an attachment.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Honored Contributor
Rita C Workman
Posts: 3,791
Registered: ‎08-03-2000
Message 11 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

..Didn't Measureware have something in a simple file that one could set these limits on../var/opt/perf/alarmdef

If memory serves me, you could set to notify for CPU,swap,disk I/O, and Filesystem utilization. Maybe, you could just add a line (under red alert) that sends an email when it hits red.

Just a thought,
Rita
Frequent Advisor
Ishwar_1
Posts: 57
Registered: ‎09-17-2009
Message 12 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

This script will check for all the filesystem with Size more then 90% and mail to the Person.

#-----------Variables
RD1=/tmp/script/check.log

#-----------Truncate
cat /dev/null > $RD1

#------------Logic
df -h | grep dev | awk '{if($5 > 90)print $5, " ", $6}' > $RD1

exec < $RD1
i=0
while read line
do
x=`cat check.log | awk '{print $1}'`
if [ "$x" > 90 ]
then
mailx # Email ID of the Person and File name $RD1
fi
i=`expr $i + 1`
done

Regards
Ishwar
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 13 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi (again):

Bill Hassell offers a nice filesystem monitoring script with notifications here:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1130400

See his commentary and attachment in the thread above.

Regards!

...JRF...
Occasional Visitor
Mohandass
Posts: 3
Registered: ‎07-04-2010
Message 14 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%


Hi Senthil,

Below is a part of my script that monitor filesystem. Hope it helps.

df -l |awk '{print $1}' > /tmp/mountlist

cat /tmp/mountlist | while read LINE
do
PERC=`df -k ${LINE} | grep allocation| awk '{print $1}'`


if [ $PERC -gt 95 ]; then

if [ $PERC -gt 98 ]; then
echo "CRITICAL ${PERC}%" | mailx -s "CRITICAL: ${LINE} on `hostname` is almost full ${PERC}%" ${SYSADM2}
else
echo "WARNING ${PERC}%" | mailx -s "WARNING: ${LINE} on `hostname` is almost full ${PERC}%" ${SYSADM2}
fi

fi

Regards
Mohan
Regular Advisor
senthil_kumar_2
Posts: 116
Registered: ‎03-02-2009
Message 15 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Hi All,

I have changed my script as follows.

#!/bin/sh
RESULTS=$(bdf | awk 'z[split($5,z,"%")-1]>90' | grep -v Filesystem)
[ -z "${RESULTS}" ] || echo "$RESULTS" | mailx -r abc@company.com -s "$HOST Filesystems > 90%" abc@company.com


Now it working fine.


Thanks a lot for all.
Regular Advisor
senthil_kumar_2
Posts: 116
Registered: ‎03-02-2009
Message 16 of 16 (524 Views)

Re: How to configure one script to send mail alerts if filesystem is reaching 90%

Please see my reply in above
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.