Using the output of bdf in script

Hello all,

First I have an old HP-UX box(11.21) for which I need to implement file-system utilization monitoring. I choosed to use bdf and a simple for loop. However sometimes the output of bdf is as this one(this is actually form linux but the idea is the same)

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vg00-rootlv  9.3G  923M  8.2G  11% /
udev                     2.5G   12K  2.5G   1% /dev
tmpfs                    995M  528K  995M   1% /run
none                     5.0M     0  5.0M   0% /run/lock
none                     2.5G     0  2.5G   0% /run/shm
/dev/mapper/vg00-tmplv   950M   30M  920M   4% /tmp
/dev/mapper/vg00-varlv
                         4.7G  615M  4.1G  13% /var
BLABLA:BLAA              950M   30M  920M   4% /home2

My question is how can I extract only the value of Use%?

The loop is something like:

usep="output from bdf"
if [ $usep -ge 90 ]
then 
echo "Fs full"
fi

I tried awk print but since we have an line with one column less this didn`t work, I have also tried cut but I cannot find universal enough delimiter as the device might be named /dev/vx/ for example or HOST:SHARE.

Any help will be greatly appreciated since I am banging my head with this almost 3h.

p.s. The power of perl is also welcome :slight_smile:

How about:

$ bdf | awk 'F{$0=F$0;F=x}NF<5{F=$0}!F{gsub(/%/,"",$5);print $1,$5}'
/dev/mapper/vg00-rootlv 11
udev 1
tmpfs 1
none 0
none 0
/dev/mapper/vg00-tmplv 4
/dev/mapper/vg00-varlv 13
BLABLA:BLAA 4
1 Like

Another way :

bdf | awk 'match($0,/[0-9]% \//) { if (int($(NF - 1)) > 90) print "Filesystem alarm " FS $(NF - 1) , $NF  } '
1 Like

Both are working great. Thank you both for the help!

On HP-UX you may find df -v easier to work with than bdf .

df -v|grep "% used blocks"|awk '{print $1,$5}'|while read fs pc
do
        if [ $pc -ge 90 ]
        then
                echo "$fs : $pc %"
        fi
done

We prefer to have a table of "normal" percentage free values and compare filesystems with this list. With pre-allocated database segments a 90% full filesystem is not a problem but root at 90% could give cause for concern.