Hi newbie01 perl,
 Try the code below and see if it works for you, it works well on my
Ultimate Ubuntu OS.
 Assumptions in the code below:
 1. you must pass df to the perl script on the Command Line Interface *e.g
perl mydf.pl df*,
 2. you don't have Perl6::Form installed, though you can get here
http://search.cpan.org/dist/Perl6-Form/, knowing the old perlform with all
it limitation is not a crime, though, I know some will disagree, making
reference to PBP.
<CODE>
*#!/usr/bin/perl -w
use strict;
use Carp;
use POSIX();

my($filesys,$mbytes,$used,$avail,$capacity,$mount)=("","","","","","");
  croak "No report file system disk space usage (df) is specified" unless
$ARGV[0];
   my $filename=$ARGV[0];
    open my $file,"$filename |" or croak "cannot open $filename:$!";
       while(defined(my $line=<$file>)){ next if $. == 1;
              chomp $line;
      ($filesys,$mbytes,$used,$avail,$capacity,$mount)=split/\s+/,$line;
        $mbytes=sprintf "%s-MB", POSIX::floor($mbytes/1024);
        $used=sprintf "%s-MB", POSIX::floor($used/1024);
        $avail=sprintf "%s-MB", POSIX::floor($avail/1024);
      write;
    }
     close $file or croak "can't close file: $!";

format STDOUT_TOP=
Filesystem            MBytes            Used            Available
Capacity        Mount
--------------------------------------------------------------------------------------------------------------------------------------
.
format STDOUT=
@<<<<<<<<<            @<<<<<<<<<<<           @<<<<<<<<<<        @<<<<<<<
    @<<<<<<<        @<<<<<<<<<<<
$filesys,        $mbytes,    $used,    $avail,        $capacity,
$mount
.*
</CODE>
Regards,
Timothy

Reply via email to