1833271 Members
3272 Online
110051 Solutions
New Discussion

Re: Script Needed

 
Hunki
Super Advisor

Script Needed

I have a need to calculate the total number of KBs that we have from the df -k output and then total them up and find out the total in GBs. Has anybody done this before ?

Thanks.
9 REPLIES 9
H.Merijn Brand (procura
Honored Contributor

Re: Script Needed

Why not use 'di?

# di -l -k -t
Filesystem Mount KBytes Used Avail %Used fs Type
/dev/hda2 / 38064816 31918884 6145932 84% reiserfs
udev /dev 388180 172 388008 0% tmpfs
Total 38064816 31918888 6145928 84%

Or in Gb

# di -gt
Filesystem Mount Gigs Used Avail %Used fs Type
/dev/hda2 / 36.3 30.4 5.9 84% reiserfs
udev /dev 0.4 0.0 0.4 0% tmpfs
Total 36.3 30.4 5.9 84%

Di is available on my site:
http://mirrors.develooper.com/hpux/downloads.html

http://mirrors.develooper.com/hpux/di-4.5-10.20.sd.bz
http://mirrors.develooper.com/hpux/di-4.5-11.00.sd.bz
http://mirrors.develooper.com/hpux/di-4.5-11.11.sd.bz
http://mirrors.develooper.com/hpux/di-4.5-11.23.sd.bz

use bzip2 to uncompress the depot

Or use perl:

# df -k | perl -pe'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"Total Gbytes: %29.2f%9.2f%9.2f\n",map{$_/1024}@x{2..4}}'
Filesystem Mount KBytes Used Avail %Used fs Type
/dev/vg00/lvol3 / 212992 54136 157656 26% vxfs
/dev/vg00/data /data 8388608 7260721 1061670 87% vxfs
/dev/vg00/lvol5 /home 32768 2280 30264 8% vxfs
/dev/vg00/opt /opt 1048576 987689 57666 95% vxfs
/dev/vg00/pro /pro 18874368 16640408 2210728 88% vxfs
/dev/vg00/lvol1 /stand 298928 48088 220944 26% hfs
/dev/vg00/tmp /tmp 524288 4358 488198 7% vxfs
/dev/vg00/u /u 1048576 466091 547783 48% vxfs
/dev/vg00/lvol7 /usr 1376256 1083376 291248 79% vxfs
/dev/vg00/lvol8 /var 4718592 815248 3873944 18% vxfs
/dev/vg00/wrk /wrk 2097152 1263035 783185 63% vxfs
Total Gbytes: 37715.92 27954.52 9495.40

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Hunki
Super Advisor

Re: Script Needed

I dont have the root privi on this box. Can it happen through df only , if possible.
H.Merijn Brand (procura
Honored Contributor

Re: Script Needed

the df-only solution was posted at the end

di for hp-ux-11.11 (temporary) available here: http://www.xs4all.nl/~procura/di

just fetch it, put it in your own /bin folder, chmod 777 di and run

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Hunki
Super Advisor

Re: Script Needed

I am atill not clear on the df solution you gave ..di is fine though.
Hunki
Super Advisor

Re: Script Needed

I am still not clear on the df solution you gave ..di is fine though.
Devesh Pant_1
Esteemed Contributor

Re: Script Needed

Hunki,
just cut and paste the command that procura has given and you will find it

DP
H.Merijn Brand (procura
Honored Contributor

Re: Script Needed

'0' points for a solution? I'm puzzled. Not that I need the points, far from that, but people will re-visit this thread, and wonder why 'di' works, but the answer does not ...

For the df solution ...

# df -k | perl -pe'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"Total Gbytes: %29.2f%9.2f%9.2f\n",map{$_/1024}@x{2..4}}'

just cut-n-paste

If you only want the last line

# df -k | perl -ne'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"Total Gbytes: %29.2f%9.2f%9.2f\n",map{$_/1024}@x{2..4}}'

(note that I just changed the invocation from -pe to -ne)

If you just want the total in Gb

total:
# df -k | perl -ne'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"%9.2f\n",$x{2}/1024}'

used:
# df -k | perl -ne'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"%9.2f\n",$x{3}/1024}'

avail:
# df -k | perl -ne'@x=split/\s+/,$_;$x{$_}+=$x[$_]for 2..4;END{printf"%9.2f\n",$x{4}/1024}'

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Hunki
Super Advisor

Re: Script Needed

Thx !

giving 6 more brother ... i gave 4 earlier ...thx again
Hunki
Super Advisor

Re: Script Needed

thx to Procura