Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

need in 'bdf' script

SOLVED
Go to Solution
Advisor

need in 'bdf' script

Hi everybody
i wrote a script that informs you about the lv usage, if the usage is more than a value.(if lv name is long 'bdf' writes some values to the next line.) my problem is, this script never gives the last value of bdf. please try it in your system. and please help. :) i think there is a small trick, but i could not find.
arper=gives %usage
arpernxt=gives %usage (if lv name is long and %usage at the next line)

export date=`date +%d_%m_%y`
set -A arper $(bdf|awk '{print $5}'|cut -f1 -d "%")
set -A arpernxt $(bdf|awk '{print $4}'|cut -f1 -d "%")

set -A armnt $(bdf|awk '{print $6}'|cut -f1 -d "%")
set -A armntnxt $(bdf|awk '{print $5}'|cut -f1 -d "%")

i=0
echo "Total number of lv:"${#arper[@]}
while (( $i < ${#arper[@]} ))
do
if [[ ${arper[$i]} > 64 || ${arpernxt[$i+1]} > 64 ]]
then
if [ ${arper[$i]} ]
then

case "${arper[$i]}" in
[0-9]*)
echo ${arper[$i]} ${armnt[$i+1]}
;;
*)
echo ${arpernxt[$i+1]} ${armntnxt[$i]}
;;
esac
fi
fi
i=$(($i+1))
done
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

Re: need in 'bdf' script

As mentioned in the reply from James, bdf does indeed break up the line into two parts. The simplest solution is to read all the values for each line and if the trailing values are empty, read again. The breakpoint for bdf is always the same. Here is a snippet of code:

bdf -l |
while read FS TOT USED AVAIL PERCENT MNT
do
if [ "$TOT" = "" ]
then
read TOT USED AVAIL PERCENT MNT
fi
print $FS $TOT $USED $AVAIL $PERCENT $MNT
done

This will normalize bdf into all 1-line strings for each mountpoint.
3 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: need in 'bdf' script

Hi:

Bill Hassell has addressed this before. See here, for instance:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=214093&admit=-682735245+1134656...

Regards!

...JRF...
Honored Contributor Honored Contributor

Re: need in 'bdf' script

As mentioned in the reply from James, bdf does indeed break up the line into two parts. The simplest solution is to read all the values for each line and if the trailing values are empty, read again. The breakpoint for bdf is always the same. Here is a snippet of code:

bdf -l |
while read FS TOT USED AVAIL PERCENT MNT
do
if [ "$TOT" = "" ]
then
read TOT USED AVAIL PERCENT MNT
fi
print $FS $TOT $USED $AVAIL $PERCENT $MNT
done

This will normalize bdf into all 1-line strings for each mountpoint.
Highlighted
Advisor

Re: need in 'bdf' script

Thank you so much.