Sponsored Content
Full Discussion: df -k to df -h
Top Forums Shell Programming and Scripting df -k to df -h Post 302205428 by matrixmadhan on Sunday 15th of June 2008 01:30:24 AM
Old 06-15-2008
Here is a sample that I wrote, you could try this

Code:
#! /opt/third-party/bin/perl

use strict;
use warnings;

use Switch;

use constant CONV_FACTOR => '1024';

sub num_to_letter {

  my $val = shift;
  my $notation;

  switch ($val) {
    case 1 { $notation = "K"; }
    case 2 { $notation = "M"; }
    case 3 { $notation = "G"; }
    else   { $notation = "Error"; }
  }

  return $notation;
}

sub num_convert {

  my $val = shift;
  my $cnt = 1;

  while ( ($val / +CONV_FACTOR) > 1 ) {
    $val /= +CONV_FACTOR;
    $cnt++;
  }

  return $val . num_to_letter($cnt);
}

my $pipeCommand = "/bin/df -k |";
open(PIPE, $pipeCommand) or die "Unable to open PIPE command $pipeCommand\n";

while(<PIPE>) {
  if( $. == 1 ) {
    print;
    next;
  }
  my @arr = split(/  */);
  for( my $i = 1; $i <= 3; $i++ ) {
    $arr[$i] = num_convert($arr[$i]);
  }
  print "@arr";
}

close(PIPE);

exit(0);

 
All times are GMT -4. The time now is 07:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy