1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 0 Filesystem (avail) ---|---|---|---|---|---|---|---|---|---| ------------------ 89 =================================== /dos (704936) 62 ======================== /usr (4555040) 62 ======================== /home/lemur (4555040) 45 ================== / (134353) #### #!/usr/bin/perl use Term::ANSIColor qw( color ); my @lines; my $df = "df"; ## Point to a Berkely-esque df if needed if ($^O =~ /solaris/) { $df = "/usr/ucb/df"; } ## Open a pipe from df open( DF, "$df @ARGV |" ) or die "Can't open pipe from df: $!"; ## skip first line scalar ; ## Print header print " 1\n", " 1 2 3 4 5 6 7 8 9 0\n", " 0 0 0 0 0 0 0 0 0 0 Filesystem (avail)\n", " ---|---|---|---|---|---|---|---|---|---| ------------------\n"; ## Parse output from df while() { chomp; my @F = split; $_ .= , @F = split if @F == 1; my( $av, $c, $fs ) = @F[3, 4,-1]; $c =~ s/(\d+)%/$1/; push @lines, [ $c, sprintf "%3d %-40s %s (%d)", $c, "=" x int($c / 2.5), $fs, $av ]; } close(DF); ## Print sorted reverse by capacity for( sort { $b->[0] <=> $a->[0] } @lines ) { my $color = ''; if ( $_->[0] >= 85 ) { $color = color( 'bold red' ); } elsif ( $_->[0] >= 70 ) { $color = color( 'bold yellow' ); } print $color, $_->[1], color('reset'), "\n"; } exit 0; __END__