Operating System - HP-UX
1834814 Members
2813 Online
110070 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"
Hein van den Heuvel
Honored Contributor

Re: grep bdf for aavail > number

In AWK mormally you count fields from the beginning of the line in.
The one liner below will handle the split lines from bdf transparantly by using NF (number of fields) to address fields relative to the end. It test for AVAIL > 4000000 and prints avail and mouintpoint.

bdf | awk '(NF<4){next} ($(NF-2) > 4000000) {print $(NF-2), $NF}'

Now if you want the filesystem printed too then it becomes more tricky. You need to remember it from the last line read with just 1 field and only pick up the current one if the re are 6 fields. Example

bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} ($(NF-2) > 4000000) {print f, $(NF-2), $NF}'

fwiw,
Hein.
Arnold Hausmann
Occasional Advisor

Re: grep bdf for aavail > number

Here's a nice little script that handles bdf's split lines nicely and formats bdf output nicely as well. We use it a lot to find out how much space is left within a certain percentage limit (the -p option).

Anyway, "dfspace | awk '{if ($4 > 40000) {print$0}}'" should produce your results and avoid the bdf 2-line limitation.
Stuff happens...that's why Jesus saves.
Bill Hassell
Honored Contributor

Re: grep bdf for aavail > number

Here is a script I call bdfmegs. It always produces a single line for every filesystem. There is a -v option for additional filesystem details (like large-files). Best of all, all the numbers are in megs, not kbytes.


Bill Hassell, sysadmin