#! /usr/bin/perl

use strict ;
use warnings ;

my $PROG = 'df' ;
my @OPTS = qw(-P -T -l) ;

my $prog = substr $0, rindex ( $0, '/' ) + 1 ;
my $Usage = <<USAGE ;
Usage: $prog [-v] [-q] [-d] [-f] [-t timeout]
option v : be verbose
option q : be quiet
option d : show debug info
option f : action ; otherwise dry-run
option t : timeout in \$timeout seconds ; no default
USAGE
sub Usage { die "$_[0]$Usage" ; }
sub Error { die "[error] $prog: $_[0]\n" ; }
sub Warn  { warn "[warn] $prog: $_[0]\n" ; }

# usage: &GetOptions(ARG,ARG,..) defines $opt_ID as 1 or user spec'ed value
# usage: &GetOptions(\%opt,ARG,ARG,..) defines $opt{ID} as 1 or user value
# ARG = 'ID' | 'ID=SPC' | 'ID:SPC' for no-arg, required-arg or optional-arg
# ID  = perl identifier
# SPC = i|f|s for integer, fixedpoint real or string argument

use Getopt::Long ;
Getopt::Long::config ( 'no_ignore_case' ) ;
my %opt = () ; Usage '' unless GetOptions
  ( \%opt, qw(v q d f t=i) ) ;
Usage("Arg count\n") if @ARGV > 0 ;

alarm $opt{t} if defined $opt{t} ;

my @CMD = ( $PROG, @OPTS ) ;

open CMD, '-|', @CMD or Error "can't popen [@CMD] ($!)" ;
my @lines = <CMD> ;
close CMD ;

shift @lines ; # discard column names

for my $line ( @lines )
  { chomp $line ;
    my @rec = split ' ', $line ;
    my $fs = pop @rec ;
    my ( $size, $perc ) = @rec [ 2, 5 ] ;
    chop $perc ;
    printf "%s size %i\n", $fs, $size ;
    printf "%s usage %i\n", $fs, $perc ;
  }
