1824970 Members
3674 Online
109678 Solutions
New Discussion юеВ

BDF notification script

 
system administrator_15
Frequent Advisor

BDF notification script

hI GUYS
scripting is not my strongest point and i am trying to get this script to work, i do believe in trying to keep things simple.
i have written a script to check the bdf output and email if the output exceeds 95%.
the problem is that although the script works and emails, it still emails if the check has produced no output due to there being no filesystems in excess of 95%.
what do i need to do to get the test to work correctly or have i made a mistake in how i am testing it.
attached is the script
regards
andrew
15 REPLIES 15
Laurent Menase
Honored Contributor

Re: BDF notification script

it is normal because if read fails ARG1 keep its value,

So you should do:
bdf | awk ' $5 >= 95 {print $5,$6 }' > /tmp/filesystem_check_file

while read ARG1 ARG2
do
echo "the following Filesystem has exceeded 90 percent and is currently at : "$ARG1", filesystem: "$ARG2" " | mailx -s "Filesystem Problem" email addressxxxxxxxxxxxxx
done< "$parameter_file"
Elmar P. Kolkman
Honored Contributor

Re: BDF notification script

I think this version might work a bit better. In your version multiple filesystems over 90% will only report the first one, for instance.
Every problem has at least one solution. Only some solutions are harder to find.
Hoefnix
Honored Contributor

Re: BDF notification script

Next one also works fine:
#######Begin
{
bdf | grep -v Filesystem | awk '{ print $1 " " $5-1 }' | while read fsys per
do
if [ $per -gt 95 ]
then
echo $fsys $per
fi
done
} | mailx -s "filesystem more then 95% used" email@yourdomain.com
######End

Regards,

Peter Geluk
Fabio Ettore
Honored Contributor

Re: BDF notification script

Hi,
I don't know why it doesn't work but in attachment you will see BDF notification script that I am using...

I hope this helps you.

Best regards,
Ettore
WISH? IMPROVEMENT!
Hoefnix
Honored Contributor

Re: BDF notification script

bdf | awk ' $5 >= 95 {print $5,$6 }' | tee $parameter_file | read ARG1

I think why its not working is that $5 contains for exmpl: "96%" and not "96"

Regards,

Peter
system administrator_15
Frequent Advisor

Re: BDF notification script

peter can you explain what you mean about containing 96% example i can not see it in the script i sent.
regards
andrew
Laurent Menase
Honored Contributor

Re: BDF notification script

Yes Peter is right,

the % make it doesn't work.
Sometimes the line is cut too.
bdf | tr "%" " "| ' ((NR>1)&&(NF>2)&& ($(NF-1) >= 50 )){print $(NF-1),$NF }'|
while read ARG1 ARG2
do
echo "the following Filesystem has exceeded 90 percent and is currently at : "$ARG1", filesystem: "$ARG2" " | mailx -s "Filesystem Problem" email addressxxxxxxxxxxxxx
done
Elmar P. Kolkman
Honored Contributor

Re: BDF notification script

What Peter meant, is that $5 in the awk statement is not only containing the numeric percentage value, but the percentage sign itself too. But I've tested and this isn't a problem for awk, it will work quite well.

I think your problem might be related with something else. Please check your bdf output if all filesystems are on 1 line of output. Sometimes (especially with NFS mounts) the output can be spread over multiple lines.
Every problem has at least one solution. Only some solutions are harder to find.
Laurent Menase
Honored Contributor

Re: BDF notification script

the % is not a problem as long as the value is lower than 100.

just test
echo "100% 1\n95% 2" |awk ' $1>95 { print $0 }'
It will print
95% 2
Hoefnix
Honored Contributor

Re: BDF notification script

Sorry for the delay, was driving home from work.

Adrew, I did not test your script, but when I was testing my script, I only did a print of $5 and saw that it include the % sign so I thougth the test on the greater or equal then 95 went wrong.

One remark on my script is that it always will send an email, also when none of the filesystems are above 95% used.
You can simply replace the mailx by a redirect in a file and test the linecount of the file before sending the mail.


Hopes this helps, regards,

Peter


Steven E. Protter
Exalted Contributor

Re: BDF notification script

Attaching my version.

Didn't have time to read the thread posting. Apologies if its redundant.

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
Sridhar Bhaskarla
Honored Contributor

Re: BDF notification script

Hi Andrew,

Using 'awk' on bdf may not give 100% results particularly if you have the longer logical volumes.

I would use df like below.

THRESHOLD=90
PERCENT=$(df -k /filesystem|awk '/allocation used/ {print $1}')

if [ $PERCENT -ge 90 ]
then
do_your_action
fi

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Gary L. Paveza, Jr.
Trusted Contributor

Re: BDF notification script

This is the one I use. In the email list, you have to remember to put the \ before the @ sign. Set the reportful value to whatever you want as a threshold value and run it
Dwyane Everts_1
Honored Contributor

Re: BDF notification script

Andrew,

Here is a portion of a script I use for disk space notifications:

# Check disk space
echo "\nChecking directory capacities:" >> $BASE/checklist.log
bdf | grep "^/dev" | while read line
do
set $line
PCT=0
PCT=$(echo $3 $2 | awk '{printf "%10.0f",$1/$2*100}')
if [ $PCT -ge 80 ] ; then
echo "$line" >> $BASE/checklist.log
echo "$line" >> $BASE/dskchecklist
fi
done
echo "\nAll directories have been checked." >> $BASE/checklist.log
echo "If necessary, the Admins have been notified." >> $BASE/checklist.log

"checklist.log" is mailed to me (it has other stuff logged into it as well.
"dskchecklist" is mailed to the "resource hogs." :)
You'll also notice my threshold is 80%.

D
Geoff Wild
Honored Contributor

Re: BDF notification script

I think there are a lot of answers to your issue here.

If you really want notification though, and can't afford HP OpenView, why not get Big Brother:

http://bb4.com/

Easy to setup, gives you notification and a web page view of current devices.

BTW - it uses df for disk threshholds.

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.