Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

df in Mb? 2

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
Anyone have a script to display the out put of df in Mb?

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
What do you mean, Mb as MegaByte or something else ?

If you are referer to MegaByte try df -h
and don't forget the man df :)

#!/bin/bash

df -f
 
Solaris don't have -h or -f, that's why I'll have to script it, if no one can help.



--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Thanks Fredrik, but I've already got the man page........

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Not perfect by a long shot:
Add a variable formatter based on length of $1
to try to get the correct formatting after the
change???


Code:
function isnumeric(fld) {
if (fld ~ /^[0-9]+/) {
      return 1
 }
return -1
}

function convert(fld, line) {
 if ( (isnumeric(fld)) ) {
     if (length(fld) > 6) {
         line = sprintf("%12.1f", fld / 1024000) " GB"
     } else if (length(fld) <= 6) {
         line = sprintf(&quot;%12.1f&quot;, fld / 1024) &quot; MB&quot;
     }
   return line
  }
return -1
}

{
  if (NR > 1) {
    for (i=2 ; i <=4 ; i++) {
        if (a = convert($i)) {
            $i = a
        }
    }
  }
  print  
}

OP:
df | awk -f ching.awk
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda2 8.4 GB 5.8 GB 2.3 GB 72% /
/dev/hda4 12.3 GB 724.5 MB 11.2 GB 7% /home
shmfs 93.1 MB 0.0 MB 93.1 MB 0% /dev/shm
/dev/MYLV/mylv 3.0 GB 760.8 MB 2.2 GB 26% /LV
//skav/tmp 2.6 GB 2.2 GB 399.3 MB 85% /mnt/smbmount
 
Mike, it's probably no help at the moment, but my understanding is that Solaris df will take the -h option from version 9.
 
This serves my purposes ...
Code:
df -k | awk '
NR==1 {printf(&quot;%s\t\tMB\t%s\t%s\t%s\t%s on\n&quot;,$1,$3,$4,$5,$6)}
NR!=1 && length($1) <= 10 {printf(&quot;%s\t\t\t%d\t%d\t%d\t%s\t\t%s\n&quot;,$1,$2/1024,$3
/1024,$4/1024,$5,$6)}
NR!=1 && length($1) > 10 {printf(&quot;%s\t%d\t%d\t%d\t%s\t\t%s\n&quot;,$1,$2/1024,$3/1024
,$4/1024,$5,$6)}'
Greg.
 
Nice Greg, but for some reason (not being an awk expert) it seems to screw up with lines containing /dev/md/dsk/d1 etc. Something obvious I'm missing? (probably!).
 
You can download the bash 2.05 pkg from Sunfreeware.com and then you'll have df with the -h option.

And yes Solaris 9 has /bin/bash as standard (if I'm correct it is an option at install with Solaris 8 ? but don't quote me on this).

I'd get the pkg installed, being a Linux groupie I'd be lost without it :¬)

Good Luck
Laurie.
 
I am not sure but I believe all you want is

df -k

granted this is in kilobytes, but the math is easy from there.

Good luck


As always we thank you for your support
Doug
 
Thanks Greg that's just what I needed

Mike

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Gregs code shud solve ur pbm.

if u want a simple script without header use this.

df -k | awk 'NR !=1 {print &quot;\t&quot;($2/1024 &quot;MB&quot;)&quot;\t\t&quot;,$0}'


with headers use this

df -k | awk 'NR==1{print &quot;\t\t\t&quot; $0}NR!=1 {print &quot;\t&quot;($2/1024 &quot; MB&quot;)&quot;\t\t&quot;,$0}'

Ramu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top