#!/bin/perl -P (chdir '/usr/adm/private/memories') || die "Can't cd."; `df >newdf`; open(Df, 'olddf'); while () { ($fs,$kbytes,$used,$avail,$capacity,$mounted_on) = split; next if $fs =~ /:/; $oldused{$fs} = $used; } open(Df, 'newdf') || die "scan_df: can't open newdf"; while () { ($fs,$kbytes,$used,$avail,$capacity,$mounted_on) = split; next if $fs =~ /:/; $oldused = $oldused{$fs}; next if ($oldused == $used && $capacity < 99); # inactive filesystem if ($capacity >= 90) { #if defined(mc300) || defined(mc500) || defined(mc700) $_ = substr($_,0,13) . ' ' . substr($_,13,1000); $kbytes /= 2; # translate blocks to K $used /= 2; $oldused /= 2; $avail /= 2; #endif $diff = int($used - $oldused); if ($avail < $diff * 2) { $mounted_on .= ' *'; } next if $diff < 50 && $mounted_on eq '/'; $fs =~ s|/dev/||; if ($diff >= 0) { $diff = '(+' . $diff . ')'; } else { $diff = '(' . $diff . ')'; } printf "%-8s%8d%8d %-8s%8d%7s %s\n", $fs,$kbytes,$used,$diff,$avail,$capacity,$mounted_on; } } rename('newdf','olddf'); #### #!/usr/bin/perl use strict; use warnings; use File::Basename; use Getopt::Std; my $name; BEGIN { $name = basename $0; sub USAGE () { <<".EOT"; } $name [options] Current options are: -m Assume mc300, mc500 or mc700 -h Print this help screen and exit .EOT } my %opts; getopts 'mh' => \%opts; print(USAGE), exit if $opts{h}; my $dir = '/usr/adm/private/memories'; my $olddf = 'olddf'; chdir $dir or die "[$name] Can't cd into `$dir': $!\n"; defined(my $newdf = qx/df/) or die "[$name] Can't run df: $!\n!"; my %oldused = map { my ($fs,undef,$used)=split; $fs =~ /:/ ? () : $fs => $used; } do { open my $df, '<', $olddf or die "[$name] Can't open `$olddf': $!\n"; <$df> }; open my $df, '<', \$newdf or die "[$name] Can't open file in memory: $!\n"; while (<$df>) { my ($fs, $kbytes, $used, $avail, $capacity, $mounted_on) = split; next if $fs =~ /:/; my $oldused = $oldused{$fs}; next if ($oldused == $used and $capacity < 99); # inactive filesystem if ($capacity >= 90) { if ($opts{m}) { substr($_,13,0) = ' ' x 8; $_ /= 2 for $kbytes, $used, $oldused, $avail; } my $diff = int($used - $oldused); $mounted_on .= ' *' if $avail < 2*$diff; next if $diff < 50 && $mounted_on eq '/'; $fs =~ s|/dev/||; $diff = '(' . ($diff >=0 ? '+' : '') . "$_)"; printf "%-8s%8d%8d %-8s%8d%7s %s\n" => $fs, $kbytes, $used, $diff, $avail, $capacity, $mounted_on; } } open my $odf, '>', $olddf or die "[$name] Can't open `$olddf': $!\n"; print $odf $newdf; __END__