Operating System - Linux
1751971 Members
4504 Online
108783 Solutions
New Discussion юеВ

Re: Displaying output from df -k in GB instead of KB

 
SOLVED
Go to solution
Patrick Ware_1
Super Advisor

Displaying output from df -k in GB instead of KB

Hello all,

Code below:

[CODE]

echo "Oracle Filesystems"
echo "------------------"
echo
for j in `df -l -k |grep total|grep ora|grep -v storage|grep -v vg00|awk '{print $1}'`
do
echo $j is `df -l -k $j |grep total|grep ora|grep -v storage|grep -v vg00|awk -F":" '{print $2}'|awk '{print $1}'` KB
done
echo

[/CODE]

Here is the output:

Oracle Filesystems
------------------

/ora_1 is 369437312 KB
/ora_2 is 369438640 KB
/ora_3 is 366768144 KB


I want to dsiplay the output of df -k in GB instead of KB. How would I do that?
24 REPLIES 24
James R. Ferguson
Acclaimed Contributor
Solution

Re: Displaying output from df -k in GB instead of KB

Hi Patrick:

Bill Hassell has a 'bdf' script which allows output in MB or GB and more importantly handles the case of multi-line output for any filesystem.

Why re-invent the wheel, when Bill offers his documented script here:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1124262

You can also select only the filesystems you want reported when you run it, just like the standard 'bdf'.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Displaying output from df -k in GB instead of KB

Bill Hassell has enhanced his "bdfmegs" script to display GB output. See:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1048509

I would think you could use that.


Pete

Pete
Tim Nelson
Honored Contributor

Re: Displaying output from df -k in GB instead of KB

James is too quick. I would also reference the Bill H. script. Works great, forum approved :)

Pete Randall
Outstanding Contributor

Re: Displaying output from df -k in GB instead of KB

And here's the latest version of "bdfmegs":

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1124262


Pete

Pete
Hein van den Heuvel
Honored Contributor

Re: Displaying output from df -k in GB instead of KB

Patrick, you have the 'right solution' already.
Good.

But indulge me, and take an other look at the original script.
It runs 6 processes on the first real line,
and then N times 6 more for each oracle mount point, for a grand total of 24 in the example, all this for data which is right there for the grab / filter all along.

Stuff like that makes performance folks cry, cringe, or snicker depending on their mood.

Check out this 'one liner'.
It does the same job with 2 commands:

df -k -l | awk 'BEGIN{print "Oracle Filesystems\n------------------\n"} END{print ""} /ora/&&!/vg00/{print $1,"is",$5,"Kb"}'

Now change the main print to printf and pass $5/1024 instead of $5 as found and voila!

In script form...

------------------
#!/bin/sh
df -k -l | awk '
BEGIN {print "Oracle Filesystems\n------------------\n"}
END {print ""}
/ora/ && !/vg00/ && !/storage/ {
printf ("%-20s is %5.1f Gb\n",$1,$5/1024)
} '
------------------

Of course it matters little for a task like posted, but it's the principle of things.

Also, I'd like to think that if the task had been solved along the lines above, then any Unix hacker in your environment, and many a Windoze person, could have handled the improvement request.

Hope this helps someone some day,
Hein van den Heuvel (at gmail dot com)
HvdH Performance Consulting




Bill Hassell
Honored Contributor

Re: Displaying output from df -k in GB instead of KB

For your example:

> /ora_1 is 369437312 KB
> /ora_2 is 369438640 KB
> /ora_3 is 366768144 KB

You can get not only the selected filesystems but also a sum total for them from bdfmegs:

echo "Oracle Filesystems"
echo "------------------"
bdfmegs -g -s /ora_*



Bill Hassell, sysadmin
Patrick Ware_1
Super Advisor

Re: Displaying output from df -k in GB instead of KB

All who have shown me bdfmegs, thank you! I like the way it works.

Hein van den Heuvel,

I like your method. Thank you too!

One thing I noticed is that I had to make the following line:

printf ("%-20s is %5.1f Gb\n",$1,$5/1024)

Look like this:
printf ("%-20s is %5.1f Gb\n",$1,$5/1024/1024)

To get true GB readings.
Patrick Ware_1
Super Advisor

Re: Displaying output from df -k in GB instead of KB

Also, you seem to be on a roll. How would one make this one more efficient:

df -l -k |grep total|grep -v ora|grep -v ebr|grep -v vg00|awk -F":" '{print $2}'|awk '{print $1}' > sizes.flatfiles
Patrick Ware_1
Super Advisor

Re: Displaying output from df -k in GB instead of KB

I figured it out:

df -k -l | awk '
/total/ && !/ora/ && !/vg00/ && !/ebr/ {
printf ("%5f\n",$5) >> "sizes.flatfiles"
} '


Too bad i can't give myself points!