Operating System - HP-UX
1753320 Members
6249 Online
108792 Solutions
New Discussion юеВ

grep bdf for aavail > number

 
Warren Cook_2
New Member

grep bdf for aavail > number

Hello all,

Would like to know how to perform bdf, grep on 'avail' column for all filesystems greater than a given size. Also want to display all columns from bdf.
So far below cmd prints all fields (no spaces) but picks only one record from bdf (the matching one, I want to test for all > 4000000):
bdf|tr -s " " ||awk '{print $1 $2 $3 $4}'cut -f 2 -d " " |grep 4000000

thx
12 REPLIES 12
Pete Randall
Outstanding Contributor

Re: grep bdf for aavail > number

Warren,

I'm reasonable certain I've seen something like this before and I'm willing to bet that I saw it in one of Bill McNamara's "Favorite Scripts" threads. Here's the first one, which also provides links to the other two. Have a look through them. Even if you don't find exactly what you're looking for, they're an invaluable resource.

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


Pete

Pete
Peter Day_2
Occasional Advisor

Re: grep bdf for aavail > number

Warren,
Try this -

for a in $(bdf |awk '{print $4}')
do
if [[ "$a" != "avail" ]]
then
if [[ $a -gt 4000000 ]]
then
echo Bigger than 4000000
fi
fi
done

Hope this works, it did on my system.
Regards,
Pete


.
RAC_1
Honored Contributor

Re: grep bdf for aavail > number

bdf|awk '{if($4>=106000) print $4}'
There is no substitute to HARDWORK
Steve Steel
Honored Contributor

Re: grep bdf for aavail > number

Hi

Since for long file system names bdf uses 2 lines this is difficult to realise easily

df -n|cut -f2 -d"("|cut -f1 -d ")"|while read line
do
xx=$(bdf $line|tail -n +2)
echo $xx|while read a b rest
do
let val=$b
if [ "$val" -gt "4000000" ]
then
echo $xx
fi
done
done|sort -n


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Mark Greene_1
Honored Contributor

Re: grep bdf for aavail > number

Try this:

IZE=512000
OLDIFS=$IFS
IFS="
"
for LINE in `bdf`; do
FIELD2=`echo $LINE|tr -s " "|awk '{print $2 }'`
FS_SIZE=`echo $FIELD2|tr -d "[:alpha:]" `
if [[ "$FS_SIZE" -ge $SIZE ]]; then
echo $LINE
fi
done
the future will be a lot like now, only later
Warren Cook_2
New Member

Re: grep bdf for aavail > number



Thank-you all for great and quick feedback ! I've tried all suggestions and will assign points shortly.

Mark, I'm using your suggestion, I can't get the IF to work. It appears to be comparing strings and always gives a true answer, so all bdf records are printed. I've tried several variations with no luck ... if you or anyone has a suggestion.

I mean this if:
if [[ "$FS_SIZE" -ge $SIZE ]]; then

thx
Kent Ostby
Honored Contributor

Re: grep bdf for aavail > number

bdf | awk '$2>4000000'
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Sridhar Bhaskarla
Honored Contributor

Re: grep bdf for aavail > number

Hi,

bdf is not my favorite for checking the utilizations due to below warning from the man page of bdf.

WARNINGS
If file system names are too long, the output for a given entry is
displayed on two lines.

This can confuse your script quite a bit. So, I would write the script using 'df' something like this

LIMIT=100000

cleanup()
{
rm -f /tmp/fs$$ /tmp/fsreport$$
}

trap cleanup 0 1 2

for FS in $(df -l|awk '{print $1}')
do
AVAIL=$(df -k $FS|awk '/free allocated Kb/ {print $1}')
if [ $AVAIL -ge $LIMIT ]
then
bdf $FS |sed '1d'
fi
done


Adjust your if's and limits accordingly.

-Sri


You may be disappointed if you fail, but you are doomed if you don't try
Kent Ostby
Honored Contributor

Re: grep bdf for aavail > number

oops .. missed the "no spaces part"

bdf | tr -s " " | awk '$2>4000000'
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"