hay every body
i need script like bdf -h in hp-ux there is no option like solaris df -h
it is only bdf -k so i need the output with GBytes
df -k | awk '{if($2>2) {v2=$2/(1024*1024) ; print $1"\t\t"v2}}'
displays the filesystem and the first column in converted GB
This logic can be continued for more columns of data.
can you explain why you used if ( $2 > 2 ) i don't understand this
I used that to get rid of the first line which held header text (at least in my implementation) from the df command. There are many other ways to do that.
Perhaps better...
df -k | awk '{if(NR==1) {print $1"\t\tGB-blocks"} else {v2=$2/(1024*1024) ; print $1"\t\t"v2}}'
which re-does the header
but $2 is coulmn and not line it is the first field in the coulmn no 2 any way thanks alot
The results on my system after a
df -k
Filesystem 1K-blocks Used .....
Thus, my excluding the 2nd field which mathematically was a 1.
See my other post for a better way, tracking based on NR (record number).
I just did the other fast, trying to show how awk and math could be used.
There is no "bdf -h" or "bdf -k" in HP-UX.
Please post the command you type to get disc free space output in normal units, the result from that command, and the expected converted output to your preferred units.
hi all thanks alot , i made script simulate bdf -h but i am biggner in shell script so may be the script you don't like it but it is work fine
the script tested in hp-ux 11iv2 in ksh shell
#!/usr/bin/ksh
bdf > /tmp/intial
cat -n /tmp/intial > /tmp/bdflist
while read line
do
a=`echo $line | awk '{ print $3 }'`
if [ -n "$a" ]
then
echo $line >> /tmp/finallist
fi
if [ -z "$a" ]
then
no=`echo $line | awk '{print $1 }' `
newid=`expr $no + 1`
newline=`sed -n "$newid p" /tmp/bdflist | sed "s/$newid//"`
echo $line $newline >> /tmp/finallist
fi
done < /tmp/bdflist
grep -i /dev/ /tmp/finallist | awk '{$1=""}1' > /tmp/bdfh
cat /tmp/bdfh | sed 's/^ //g' | awk '/\//{printf("%-40s%-20s%-20s%-20s%-10s%-20s\n",$1,$2,$3,$4,$5,$6)}' > /tmp/final
rm /tmp/intial /tmp/bdfh /tmp/bdflist /tmp/finallist
echo "FILESYSTEM\t\t\tGbytes\t\tused\t\tavail\t\t%used\t\tMounted"
while read line
do
total=`echo $line | awk {'printf ("%.2f", $2 / 1048576 )'}`
used=`echo $line | awk {'printf ("%.2f", $3 / 1048576 )'}`
avl=`echo $line | awk {'printf ("%.2f", $4 / 1048576 )'}`
x1=`echo $line | awk {'print $1'}`
x5=`echo $line | awk {'print $5'}`
x6=`echo $line | awk {'print $6'}`
echo "$x1\t\t\t$total"GB"\t\t$used"GB"\t\t$avl"GB"\t\t$x5\t\t$x6 "
done < /tmp/final
rm /tmp/final
any one tried this script can suggest any thing ?