--- parse_df.pl 2002/07/16 14:39:53 1.6 +++ parse_df.pl 2002/07/18 10:23:24 1.7 @@ -20,22 +20,37 @@ my $ssh = shift @ARGV || ""; my $mount = shift @ARGV || "/"; -my %df; +# do we have Cache::FileCache installed? + +my $USE_CACHE = 0; +eval("use Cache::FileCache;"); +if (! $@) { $USE_CACHE = 1; } + +my $df; + +my $cache = new Cache::FileCache() if ($USE_CACHE); sub parse_df { my $ssh = shift @_; - open(DF,"$ssh df -k |") || die "$ssh df: $!"; + if ($USE_CACHE) { + print STDERR " [using cache] "; + $df = $cache->get( $ssh ); + return if (defined $df); + print STDERR " [cache miss] "; + } + open(DF,"$ssh df -klP |") || die "$ssh df: $!"; while() { chomp; my ($node,$total,$used,$aval,$use_pcnt,$mount) = split(/\s+/,$_,6); if ($use_pcnt && $use_pcnt =~ s/(\d+)%/$1/) { # print STDERR "$_\n"; -# $df{$mount}=$use_pcnt; - $df{$mount}=$used * 100 / $total if ($total != 0); -# print $df{$mount}," == $use_pcnt\n"; +# $df->{$mount}=$use_pcnt; + $df->{$mount}=$used * 100 / $total if ($total != 0); +# print $df->{$mount}," == $use_pcnt\n"; } } close(DF); + $cache->set( $ssh, $df, "1 min" ) if ($USE_CACHE); } parse_df($ssh); @@ -49,7 +64,7 @@ EOF my @targets; - foreach my $mnt (keys %df) { + foreach my $mnt (keys %{$df}) { my $target = $mnt; if ($mnt eq "/") { $target = "root"; @@ -76,5 +91,5 @@ # dump free % # -print $df{$mount} || "unknown"; +print $df->{$mount} || "unknown"; print "\n";