- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: disk space usage in % till 2 decimal places
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
тАО08-10-2009 05:28 PM
тАО08-10-2009 05:28 PM
/dev/mapper/system-scratch_lv
436797008 156839748 257769228 38% /scratch
Can i get the value as 38.xx% instead of just 38%
I need to use df -k in a script and to get the value in decimal.
Solved! Go to Solution.
- Tags:
- bdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 06:10 PM
тАО08-10-2009 06:10 PM
Re: disk space usage in % till 2 decimal places
Can you try with this
bdf /filesystemname | tail -1 | awk '{print $3 * 100 / $2}'
for example
# bdf /var | tail -1| awk '{print $3 * 100 / $2}'
3.40014
it will give the utilization in % with decimal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 06:14 PM
тАО08-10-2009 06:14 PM
Solutiondf -k /opt
/opt (/dev/vg00/lvol6 ) : 2042016 total allocated Kb 943400 free allocated Kb
1098616 used allocated Kb
Are you referring to bdf?
bdf /opt
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol6 2048000 1098616 943400 54% /opt
In either case, these tools (df,bdf) are hardcoded with an integer percentage. To get decimal values, use awk with printf and compute the value from the numbers:
echo "/dev/stuff 436797008 156839748 257769228 38% /scratch" | awk '{printf "%4.2f \n",$3/$2*100.0}'
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 06:49 PM
тАО08-10-2009 06:49 PM
Re: disk space usage in % till 2 decimal places
Can you please explain how exactly this line works.. just for my knowledge
please explain awk '{printf "%4.2f \n",$3/$2*100.0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 08:00 PM
тАО08-10-2009 08:00 PM
Re: disk space usage in % till 2 decimal places
Can you please explain how exactly this line works.. just for my knowledge
please explain awk '{printf "%4.2f \n",$3/$2*100.0}'
Bill- Thanks for the solution. It worked just fine. I am using it in linux.
Can you please explain how exactly this line works.. just for my knowledge
please explain awk '{printf "%4.2f \n",$3/$2*100.0}'
'{}' loops over each input line and unconditionally executes the code in the block{ }
Each line is split in 'words' seperate by 'whitepace'
Printf... like the C ( perl / shell) function.
%4.2f : 4 position float with 2 characters precision.
$3 : word 3
$1 : word 2
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-10-2009 10:27 PM
тАО08-10-2009 10:27 PM
Re: disk space usage in % till 2 decimal places
Example:
# more a1
20 30 40
10 40 800
# awk '{printf "%4.2f \n",$3/$2*100.0}' a1 <<== %4.2
133.33
2000.00
# awk '{printf "%4.3f \n",$3/$2*100.0}' a1 <<== %4.3
133.333
2000.000
In first line of file 'a1':
$2 = 30 (2nd input)
$3 = 40 (3rd input)
%4.2 --> two decimal palces
%4.3 --> three decimal palces
\n --> change line
C language works well with Awk.
More info on awk with examples:
http://www.vectorsite.net/tsawk_1.html#m1
Regds..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2009 01:59 AM
тАО08-11-2009 01:59 AM
Re: disk space usage in % till 2 decimal places
If you want to inline replace the percentage shown with a decimal number you can modify the 'awk' solution slightly. In this case the contents of the original line are preserved :
# echo "/dev/stuff 436797008 156839748 257769228 38% /scratch" | awk '{$5=sprintf "%4.2f",$3/$2*100.0;print}'
/dev/stuff 436797008 156839748 257769228 35.91 /scratch
The 'sprintf' function creates a string instead of printing. Here we assign the string value back to the fifth ($5) field, replacing its original value. Then, we simply print the modified line.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2009 12:37 PM
тАО08-11-2009 12:37 PM