Operating System - HP-UX
1753494 Members
5085 Online
108794 Solutions
New Discussion юеВ

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

 
SOLVED
Go to solution
senthil_kumar_2
Regular Advisor

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.



15 REPLIES 15
James R. Ferguson
Acclaimed Contributor

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...
James R. Ferguson
Acclaimed Contributor

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...

Suraj K Sankari
Honored Contributor

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&threadId=1130400
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
senthil_kumar_2
Regular Advisor

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.
James R. Ferguson
Acclaimed Contributor

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...
senthil_kumar_2
Regular Advisor

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.

James R. Ferguson
Acclaimed Contributor

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...
Dennis Handly
Acclaimed Contributor
Solution

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
Steven E. Protter
Exalted Contributor

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