df -k to df -h


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting df -k to df -h
# 1  
Old 06-14-2008
df -k to df -h

Hi expert,
We have an old Solaris box and there's no -h available in df command.
Could you show me how to convert -k to -h in script ?
Thanks.
# 2  
Old 06-15-2008
Would you mind posting the solaris version ?
# 3  
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);

# 4  
Old 06-15-2008
5.5.1 meaning 2.5.1 right ?
I'll try and let you know. I need to install perl first.
# 5  
Old 06-15-2008
Quote:
5.5.1 meaning 2.5.1 right ?
Sorry, I didn't understand that.

Could you please rephrase or elaborate on that ?
# 6  
Old 06-15-2008
SunOS 5.5.1 ( or ) Solaris 2.5
# 7  
Old 06-15-2008
syntax error in file ./dfh.pl at line 2, next 2 tokens "use strict"
syntax error in file ./dfh.pl at line 11, next 2 tokens "my $val "
syntax error in file ./dfh.pl at line 16, next 2 tokens "case 2"
syntax error in file ./dfh.pl at line 34, next 2 tokens "num_to_letter("
syntax error in file ./dfh.pl at line 38, next 2 tokens ") or"
syntax error in file ./dfh.pl at line 45, next 2 tokens "my @arr"
syntax error in file ./dfh.pl at line 46, next 2 tokens "my $i "
syntax error in file ./dfh.pl at line 47, next 2 tokens "num_convert("
Execution of ./dfh.pl aborted due to compilation errors.


===================================================
below is the path and version of perl i use

/tivoli/bin/solaris2/contrib/bin/perl
/tivoli/bin/solaris2/contrib/lib/perl
/tivoli/bin/lcf_bundle/bin/aix4-r1/tools/bin/perl
/tivoli/bin/lcf_bundle/bin/aix4-r1/tools/lib/perl
/tivoli/bin/lcf_bundle/bin/hpux10/tools/bin/perl
/tivoli/bin/lcf_bundle/bin/hpux10/tools/lib/perl
/tivoli/bin/lcf_bundle/bin/os2-ix86/tools/lib/perl
/tivoli/bin/lcf_bundle/bin/solaris2/tools/bin/perl
/tivoli/bin/lcf_bundle/bin/solaris2/tools/lib/perl
/tivoli/bin/lcf_bundle/bin/sunos4/tools/bin/perl
/tivoli/bin/lcf_bundle/bin/sunos4/tools/lib/perl
/tivoli/bin/lcf_bundle/bin/w32-ix86/tools/lib/perl

-----------------------------------
#/tivoli/bin/lcf_bundle/bin/solaris2/tools/bin/perl -v

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 1.1 $$Date: 1996/05/10 05:06:54 $
Patch level: 36

Copyright (c) 1989, 1990, 1991, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question