Re: Blocks verses Bytes,Mbytes etc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In case anyone should want to do this quickly here is a clumsy little
perl script that does it.  It'd have to be reworked if used against
more than one disk at once as in fdisk -l.  Or with other versions of
fdisk. 

cat fdiskcnv

#!/usr/bin/perl -w

# Keywords: fdiskcnv - designed to convert fdisk -l output to approx.
# MB equivalents. Script Runs `fdisk -l' inside perl and converts
# the block values to Mbyte values in a second printout.
# Apr 29 2003 2
# &&

$cmd = 'fdisk -l';
open(FDISKL,"$cmd |");
while(<FDISKL>){
  print;
  chomp;
  my $line = $_;
  if(/^\/dev\//){
    $readem = "TRUE";
  }
  if(!/^\/dev\//){
    $readem = '';
  }

  if ($readem && /\s+\*\s+/){
  ## if we see the asterisk grab field5
  ## and get rid of any + signs by making + a split field 
    ($fld0,$fld4) = (split(/\s+|\+/))[0,4];
    $var = sprintf "%-12s %s %.2f\n","$fld0 " , "MB" , ($fld4 / 1024);
    push @MB_ar, "$var";
  }elsif($readem && $line !~ /\*/){
    ($fld0, $fld3) = (split(/\s+|\+/))[0,3];
    $var = sprintf "%-12s %s %.2f\n","$fld0 ", "MB" , ($fld3 / 1024);
    push @MB_ar, "$var";
  }
}
close(FDISKL);
print "\n== Approximate Mbyte equivalents ====\n\n";
for(@MB_ar){
  print;
}





[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux