Operating System - HP-UX
1748244 Members
4152 Online
108760 Solutions
New Discussion юеВ

Re: help regarding bdf output shell script !!!!

 
SOLVED
Go to solution
Pravin Salgaonkar
Frequent Advisor

help regarding bdf output shell script !!!!

Hi,
I have written a funtion which taken bdf output and put's in a file.
The idea is to get all areas greater than 80% and echo the same on the system once they have reached 80 % limit. However the script I have written fails with the error.

The script is :-

======================================
output ()
{/usr/bin/bdf -l |awk '$0 !~ /^F/' |awk '{print $5"\t" $6}'| sed 's/'%'/''/' >/tmp/bdflist}

panic ()
{while read percent dir
do
if [[ $percent -ge 80 ]]
then
echo "File syste Full - `hostname`:$dir is at $percent%"
fi
done} < /tmp/bdflist
output
panic
===========================================
+ awk $0 !~ /^F/
+ awk {print $5"\t" $6}
+ sed s/%//
+ 1> /tmp/bdflist}
./test[8]: Syntax error at line 9 : `do' is not expected.

Please assist in resolving the same.
Thanking you in advance
13 REPLIES 13
Court Campbell
Honored Contributor

Re: help regarding bdf output shell script !!!!

here is a simple script i use written in perl. feel free to change it up.

$mailto = 'some@email_addr.com';
$hostname = `hostname`;
@mounts = `bdf`; #puts bdf info into seperate array elements

foreach (@mounts){
if ($_ =~ /100%|9[0-9]|8[0-9]%/) {
$fs = $';
chop $fs;
$mesg .= "$fs is at $&.\n";
}
}

if ($mesg) {
`echo "$mesg" | mailx -s "$hostname Filesystem Warning" $mailto`;
}
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Hasan  Atasoy
Honored Contributor

Re: help regarding bdf output shell script !!!!

output ()
{
/usr/bin/bdf -l |awk '$0 !~ /^F/' |awk '{print $5"\t" $6}'| sed 's/'%'/''/' >/tmp/bdflist
}

panic ()
{
cat /tmp/bdflist | while read percent dir
do
if [[ $percent -ge 80 ]]
then
echo "File syste Full - `hostname`:$dir is at $percent%"
fi
done
}
output
panic
Court Campbell
Honored Contributor
Solution

Re: help regarding bdf output shell script !!!!

noticed a mistake

($_ =~ /100%|9[0-9]|8[0-9]%/)

should be

($_ =~ /100%|9[0-9]%|8[0-9]%/)

"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Geoff Wild
Honored Contributor

Re: help regarding bdf output shell script !!!!

Try:

/usr/bin/bdf -l |awk '$0 !~ /^F/' |awk '{print $5"\t" $6}'| sed 's/'%'/''/'|
while read percent dir
do
if [[ $percent -ge 80 ]]
then
echo "File syste Full - `hostname`:$dir is at $percent%"
fi
done


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

Re: help regarding bdf output shell script !!!!

Hi:

The simple fix, is to place the curly braces for each function on a line by themselves:

...
output ()
{
/usr/bin/bdf -l |awk '$0 !~ /^F/' |awk '{print $5"\t" $6}'| sed 's/'%'/''/' >/tmp/bdflist
}
panic ()
{
while read percent dir
do
if [[ $percent -ge 80 ]]
then
echo "File syste Full - `hostname`:$dir is at $percent%"
fi
done
} < /tmp/bdflist
output
panic

...

This script could/should be rewritten to eliminate using temporary files (pipe output to the 'read') and should let ONE 'awk' do the work of matching and extracting (consider using 'awk's 'split').

For a simple script like this, in-lining your code like Geoff suggested is probably a more-readable approach.

Regards!

...JRF...
john korterman
Honored Contributor

Re: help regarding bdf output shell script !!!!

Hi,

include a shell interpreter and a few newlines:

#!/usr/bin/sh
output ()
{
/usr/bin/bdf -l |awk '$0 !~ /^F/' |awk '{print $5"\t" $6}'| sed 's/'%'/''/' >/tm
p/bdflist
}

panic ()
{
while read percent dir
do
if [[ $percent -ge 80 ]]
then
echo "File syste Full - `hostname`:$dir is at $percent%"
fi
done < /tmp/bdflist
}

output
panic


regards,
John K.
it would be nice if you always got a second chance
spex
Honored Contributor

Re: help regarding bdf output shell script !!!!

The latest version of Bill Hassell's bdfmegs shell script includes a '-P ' option to suppress output for filesystems with utilization <= pct. You can grab it from this thread:

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

PCS
Bill Hassell
Honored Contributor

Re: help regarding bdf output shell script !!!!

One of the problems with bdf is that it automatically wraps a line if the source disk name is too long and this messes up all the numbers. My bdfmegs script can be run with any headers and show just the problem mountpoints. You can select the maximum percentage:

bdfmegs -qP 90

Only the mountpoints that are greater than or equal to 90% full will be shown.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: help regarding bdf output shell script !!!!

Clarification: bdfmegs always shows each mountpoint on a single line making it ideal for scripting. I have attached the script here.


Bill Hassell, sysadmin