In a similar vein to disk monitor, I had this lying around. It parses the output from df to produce a bar graph of disk usage. Term::ANSIColor is used to highlight partitions that are really full (85% or more) or almost full (75-85%).

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)

Tested on Linux, FreeBSD, OpenBSD, and Solaris.

#!/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 <DF>; ## 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(<DF>) { chomp; my @F = split; $_ .= <DF>, @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__

Replies are listed 'Best First'.
Re: disk usage graph (dfgraph)
by belg4mit (Prior) on Nov 17, 2001 at 06:10 UTC
    Zut! My post a few earliers got lost (may have been when I crashed). Anyways, pretty cool just wondering if you had considered Text::BarGraph/Text::BarGraph

    -- perl -p -e "s/(?:\w);(<A HREF="/index.pl?node=st&lastnode_id=3333">st< +/A>)/'\$1/mg"

      This was written as a quick hack almost two years ago now, so no. Wasn't even aware of its existence (CPAN never ceases to amaze . . . :).

Re: disk usage graph (dfgraph)
by AltBlue (Chaplain) on Nov 20, 2001 at 21:55 UTC
    I would consider using a PERL module for gathering disk usage rather than parsing output of a system tool. I've used Filesys::DiskSpace in the past and it was quick and good enough at that time.

    --
    AltBlue.

Re: disk usage graph (dfgraph)
by coec (Chaplain) on Mar 02, 2002 at 11:38 UTC
    Slight changes required under AIX...
    Change my( $av, $c, $fs ) = @F[3, 4, -1]; to my( $av, $c, $fs ) = @F[5, 3, -1];