Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ?? (974 Views)
Super Advisor
Posts: 395
Registered: ‎10-20-1998
Message 1 of 8 (974 Views)

# bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

bdf | awk '{ sum += \$2; } END { print sum; }'
gives me 5.03521e+07

Not sure what that means. How can I get output in Megbytes ?
good judgement comes from experience and experience comes from bad judgement.
Acclaimed Contributor
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

Hi Sammy:

This is simply scientific notation. This is 5.03521 times 10 raised to the 7th power:

50,352,100

To obtain megabytes (ideally) divide by 1024/1024 or:

# bdf | awk '{ sum += \$2; } END { print sum/1024/1024; }'

Regards!

...JRF...
Acclaimed Contributor
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

Hi (again) Sammy:

I would also direct you to this article and its links which show that the terms 'mega', 'giga', etc. become imprecise as the magnitude of numbers increase. A acccurate terminology is 'mebi'byte, here:

http://en.wikipedia.org/wiki/Mebibyte

Regards!

...JRF...
Super Advisor
Posts: 395
Registered: ‎10-20-1998
Message 4 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

JRF, Thanks and it got what i needed. But, is it a typo or 1024/1024 in your solution would give you in GB as oppose to MB
good judgement comes from experience and experience comes from bad judgement.
Acclaimed Contributor
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

Hi Sammy:

Ooops, sorry, I'm thinking giga/gibi bytes :-)

NO POINTS PLEASE!

...JRF...
Acclaimed Contributor
Posts: 21,184
Registered: ‎07-06-2000
Message 6 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

Sammy:

Now that I have had coffee and lunch, after a long night, I would suggest you amend your formatting to round your values, too. The 'printf' function accomodates this. Too, I would also instruct 'awk' to skip the first record (the header line from 'bdf') as a cleaner implementation, although in this case there is no second field in the header.

# bdf | awk 'NR>1 {sum+=\$2};END {printf "%5.0f MB\n",sum/1024}'

No points are necessary for what I ahould have added the first time!

Regards!

...JRF...
Honored Contributor
Posts: 6,593
Registered: ‎05-19-2003
Message 7 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

Sammy,

If BDF does the job for you, then more power to you! However, several of us run into issues with it due to the bonus line-wrapping it does for long names.

See for example:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=542488

So you may want to build a serious script with DF looking for field \$4 or "dk -k" looking for field \$5 on lines with "total"

Also... you want to count NFS mounts?

Consider using bdf | awk '/^.dev/{ sum...
# The "^" anchors te search to the begin of line.
# The "." is a cheat place holder for /

fwiw,
Hein.
Highlighted
Honored Contributor
Posts: 14,413
Registered: ‎05-29-2000
Message 8 of 8 (974 Views)

# Re: bdf | awk '{ sum += \$2; } END { print sum; }' for total space in Megabytes ??

This script will probably give you everything you need. You can even select the mountpoints for a summary, like this: bdfmegs -s /dev/vg00/lvol* Here is the usage:

Usage: bdfmegs [ -glPpqstvu ] [ dir(s) or file(s) ]
where:
-g = gigabytes rather than megabytes
-l = local only (not NFS)
-p ## = highlight pct -ge ##
-P ## = same as -p but show only pct -ge ##
-q = suppress the header line and no char enhancements
-s = summary of total, used and available
-t xxxx = specifc filesystem (hfs vxfs nfs cdfs cifs autofs DevFS)
-u = usage details (return code = 0, usage text to stdout)
-v = verbose (shows FSversion, largefiles flag)
(requires read permission for mountpoint)

File(s) or dirpath(s) may be specified to limit
the output of bdfmegs as in:

bdfmegs -vlg /usr/contrib/bin /var/tmp

If bdfmegs is run as bdfgigs (ie, a link), then -g is default.
(bdfmegs ver 4.7)
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.