1831455 Members
3188 Online
110025 Solutions
New Discussion

Re: total disk usage

 
hpuxrox
Respected Contributor

total disk usage

How would one total the kbytes used from the bdf command?
13 REPLIES 13
Mel Burslan
Honored Contributor

Re: total disk usage

total=0
bdf | grep -v ^Filesystem | while read line
do
used=`echo $line | awk {'print $2'}`
(( total=$total+$used ))
done
echo $total " kilobytes of used disk space"

hope this is what you are looking for.
________________________________
UNIX because I majored in cryptology...
Aussan
Respected Contributor

Re: total disk usage

you would add the used kb but bdf is not a good way to see the disk usage because nfs mount are not on your system and they should not count

lets say you wanted to find out how much disk usage is on vg00, you would do vgdisplay vg00 and you would take Alloc PE number * PE Size (Mbytes) that would give you how much disk is being used in MB
The tongue weighs practically nothing, but so few people can hold it
Sandman!
Honored Contributor

Re: total disk usage

# bdf | awk '{tot+=$2}END{printf("total kbytes %d\n",tot)}'
Court Campbell
Honored Contributor

Re: total disk usage

bdf | grep -v File | awk '{x=$2;x+=x}END{printf "%d\n",x}'
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: total disk usage

scratch that it should be:

bdf | grep -v File | awk '{x+=$2}END{printf "%d\n",x}'
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
A. Clay Stephenson
Acclaimed Contributor

Re: total disk usage

First, look around on the Forums for one of Bill's scripts called bdfmegs because it's gonna fix a problem that you ain't thought of yet.

Then:
--------------------------------------------
#!/usr/bin/sh

build_A1()
{
echo "/^Filesystem/ { next}"
echo "{"
echo " v1 += (\$2 + 0); v2 += (\$3 + 0); v3 += (\$4 + 0)"
echo "}"
echo "END {"
echo " print v1,v2,v2"
echo "}"
return 0
} # build_A1

A1=$(build_A1)
bdfmegs | awk "${A1}"
--------------------------------------------
This will actually sum all three of the values but you should easily be able to adapt it to your exact needs.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: total disk usage

Hi:

# bdf|awk '{if (NR>1) {USED+=$3}};END{print USED}'

Regards!

...JRF...
hpuxrox
Respected Contributor

Re: total disk usage

I am running into limitations in awk, it can not calculate that high of a number. Anyways to do it in perl or bc?
Court Campbell
Honored Contributor

Re: total disk usage

arrgh, you stated used space.

bdf | grep -v File | awk '{x+=$3}END{printf "%d\n",x}'
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
James R. Ferguson
Acclaimed Contributor

Re: total disk usage

Hi (again):

OK, you would like Perl (I do too!):

# bdf|perl -nle 'if ($.>1) {@f=split;$used+=$f[2]};END{print $used}'

...Note that Perl numbers things 0-relative unlike 'awk' which counts its split fields as 1-relative. This too, skips the header line of the 'bdf'.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: total disk usage

Dummy!

That's why I suggested bdfmegs and not only will it solve the problem you've now discovered; it will also solve the one that you haven't discovered.

Anyway, here's a copy of Bill's bdfmegs script.

If it ain't broke, I can fix that.
Sandman!
Honored Contributor

Re: total disk usage

What limitations? Could you post the output from the one-liners.
hpuxrox
Respected Contributor

Re: total disk usage

.