- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Displaying output from df -k in GB instead of ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 05:49 PM
тАО09-13-2007 05:49 PM
Re: Displaying output from df -k in GB instead of KB
My script reported Mb, not Gb.
>> I figured it out:
Excellent.
>> Too bad i can't give myself points!
Just find grab a query I created and say hello! Nah...
Seriously, I am very pleased you considered the alternative and checked out how it worked. Good work!
I had wondered whether it would be a total waste of time to add my reply, but couldn't help myself. No I'm redeemed :-).
As reward I'll show how to do grand total. :-).
I added a variable t (total) which accumulated all KB values in the main code.
Then at the end, where previously is printed just an empty line, it now prints that total.. divived by 1M.
#!/bin/sh
bdf -k -l | awk '
BEGIN {print "Oracle Filesystems\n------------------\n"}
END {printf ("\nTotal %3.1fGb\n\n", t/1024/1024)}
/ora/ && !/vg00/ && !/storage/ {
t+=$5;
printf ("%-20s is %5.1f Gb\n",$1,$5/1024/1024)
} '
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 05:55 PM
тАО09-13-2007 05:55 PM
Re: Displaying output from df -k in GB instead of KB
df -l -k |grep total|grep -v ora|grep -v ebr|grep -v vg00|awk
If you want to do a part way job, you can combine the grep -v:
df -l -k |grep total|grep -v -e ora -e ebr -e vg00 | awk
You may have to be careful if your strings are found as substrings. You can add -w to fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 06:16 PM
тАО09-13-2007 06:16 PM
Re: Displaying output from df -k in GB instead of KB
# df -l -k /ora05 | grep total
/ora05 (/dev/vg05/lvol1 ) : 368868648 total allocated Kb
# df -l -k /ora06 | grep total
/ora06 (/dev/vg06/lvol1) : 366767600 total allocated Kb
If you look at the middle part where the logical volume is listed on each, you can see a difference that will throw awk off. In the first listing, there is a space between the lvol name , and the closing parenthesis ")". In the second listing, there is no space. This means that the $5 is the word "total" instead of the numerical size. As a result of this, I see that the calculations are off like below due to this extra space:
/ora05 is 360223.289 Mb
/ora06 is 0.000 Mb
Do you know how to account for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 06:24 PM
тАО09-13-2007 06:24 PM
Re: Displaying output from df -k in GB instead of KB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 07:29 PM
тАО09-13-2007 07:29 PM
Re: Displaying output from df -k in GB instead of KB
You should be able to do $(NF-3) to get that field.
$ df -l -k | grep total | awk '{print $(NF-3)}'
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2007 11:45 PM
тАО09-13-2007 11:45 PM
Re: Displaying output from df -k in GB instead of KB
Seeing 'grep' in a pipeline to 'awk' says you are WASTING resources. 'awk' is a pattern-matching engine!
>Dennis: You should be able to do $(NF-3) to get that field.
$ df -l -k | grep total | awk '{print $(NF-3)}'
Eliminate the extra process:
# df -l -k | awk '/total/ {print $(NF-3)}'
...You even save your fingers from typing :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 02:40 AM
тАО09-14-2007 02:40 AM
Re: Displaying output from df -k in GB instead of KB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 02:56 AM
тАО09-14-2007 02:56 AM
Re: Displaying output from df -k in GB instead of KB
df -k -l | awk '
/total/ && !/ora/ && !/vg00/ && !/ebr/ {
printf ("%5f\n",$(NF-3)) >> "sizes.flatfiles"
} '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 02:11 PM
тАО09-14-2007 02:11 PM
Re: Displaying output from df -k in GB instead of KB
df -k -l | awk '
BEGIN {print "\nFlat Files\n------------------" >> "sizes.report"}
END {printf ("\n------------------\nTotal %3.3f Tb\n\n", t/1024/1024/1024) >> "sizes.report"}
/total/ && !/ora/ && !/vg00/ && !/ebr/ {
t+=$(NF-3);
printf ("%-35s is %5.3f Gb\n",$1,$(NF-3)/1024/1024) >> "sizes.report"
} '
df -k -l | awk '
BEGIN {print "\nOracle Filesystems\n------------------" >> "sizes.report"}
END {printf ("\n------------------\nTotal %3.3f Tb\n\n", t/1024/1024/1024) >> "sizes.report"}
/total/ && /ora/ && !/vg00/ && !/storage/ {
t+=$(NF-3);
printf ("%-35s is %5.3f Gb\n",$1,$(NF-3)/1024/1024) >> "sizes.report"
} '
df -k -l | awk '
BEGIN {print "\nEBR Filesystems\n------------------" >> "sizes.report"}
END {printf ("\n------------------\nTotal %3.3f Tb\n\n", t/1024/1024/1024) >> "sizes.report"}
/total/ && /ebr/ && !/vg00/ {
t+=$(NF-3);
printf ("%-35s is %5.3f Gb\n",$1,$(NF-3)/1024/1024) >> "sizes.report"
} '
The code above creates sizes.report
sizes.report output:
---------------------------------------------
Flat Files
------------------
/usr/local is 2.291 Gb
/usr/local2 is 0.118 Gb
/var/mqm is 9.170 Gb
------------------
Total 0.011 Tb
Oracle Filesystems
------------------
/usr/local/oracle/10.2.0 is 7.795 Gb
/usr/local/oracle/9.2.0 is 5.686 Gb
/usr/local/oracle is 5.708 Gb
/usr/local/oracle2 is 1.907 Gb
------------------
Total 0.020 Tb
EBR Filesystems
------------------
/opt/app/ebr1 is 2029.520 Gb
/opt/app/ebr2 is 2029.520 Gb
/opt/app/ebr3 is 2029.520 Gb
/opt/app/ebr4 is 2031.505 Gb
/opt/app/ebr5 is 2029.520 Gb
/opt/app/ebr6 is 2029.520 Gb
------------------
Total 11.894 Tb
---------------------------------------------
end sizes.report output
The code below processes the file, and outputs a total of the totals:
cat sizes.report | awk '
BEGIN {print "\nTotal Of All \n------------------" >> "sizes.report"}
END {printf ("\nTotal %3.3f Tb\n\n", t) >> "sizes.report"}
/Total/ {
t+=$(NF-1);
#printf ("%5.3f Tb\n",$(NF-1) >> "sizes.report")
} '
The result is appended to the end of the file sizes.report:
Total Of All
------------------
Total 11.925 Tb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2007 03:58 PM - edited тАО09-24-2011 06:13 PM
тАО09-14-2007 03:58 PM - edited тАО09-24-2011 06:13 PM
Re: Displaying output from df -k in GB instead of KB
>Made another variation of Hein van den Heuvel's grand total script:
Here is why you want to use grep and awk. You have three scripts that are very much alike. While you can use awk -v to pass in your report title (or do it outside), it is harder to get your RE to take a variable.
See my solution in this thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1158757
If you want the patterns to be variables:
awk -v p1="^003" -v p2="^abc" -v p3="^a13" -v p4="^next" '
$0 ~ p1 || $0 ~ p2 || $0 ~ p3 {
You can also have functions in awk.