Fixed some more parsing problems. Added beginning of a test suite.
This commit is contained in:
parent
b7acf57799
commit
71d8515467
|
@ -88,30 +88,12 @@ sub sendmail
|
|||
print SENDMAIL "$msg\r\n";
|
||||
}
|
||||
|
||||
getopts('ad', \%opts);
|
||||
|
||||
$hostname=`hostname`;
|
||||
chomp($hostname);
|
||||
open (DF, "@@@df@@@ |") or die "cannot call @@@df@@@: $!";
|
||||
|
||||
my $fs = $/;
|
||||
undef ($/);
|
||||
my $df = <DF>;
|
||||
close(DF);
|
||||
$/ = $fs;
|
||||
|
||||
$df =~ s/\n[ \t]+/ /mg;
|
||||
my @df = split(/\n/, $df);
|
||||
for my $ln (@df) {
|
||||
my ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln);
|
||||
if ($fs =~ m|^/dev/|) {
|
||||
my $mount_t = $mount;
|
||||
$mount_t =~ s|/|_|g;
|
||||
open REPQUOTA, "@@@repquota@@@ $mount 2>/dev/null |" or die "cannot call @@@repquota@@@: $!";
|
||||
sub parseline($$) {
|
||||
my ($mount, $line) = @_;
|
||||
local $_ = $line;
|
||||
my $hpuxtime = '(?:NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))';
|
||||
my $linuxtime = '(?:none|\d+\:\d+|\d+days)';
|
||||
while (<REPQUOTA>) {
|
||||
next unless (/\b\d+\b/); # ignore header lines
|
||||
return undef unless (/\b\d+\b/); # ignore header lines
|
||||
my $msg = "";
|
||||
my $user;
|
||||
if (/(\w+) \s+ -- \s*
|
||||
|
@ -148,6 +130,38 @@ for my $ln (@df) {
|
|||
print "$mount: $.: unparseable: $_";
|
||||
next;
|
||||
}
|
||||
return ($user, $msg);
|
||||
}
|
||||
|
||||
getopts('adt', \%opts);
|
||||
|
||||
if ($opts{t}) {
|
||||
selftest();
|
||||
}
|
||||
|
||||
$hostname=`hostname`;
|
||||
chomp($hostname);
|
||||
open (DF, "@@@df@@@ |") or die "cannot call @@@df@@@: $!";
|
||||
|
||||
my $fs = $/;
|
||||
undef ($/);
|
||||
my $df = <DF>;
|
||||
close(DF);
|
||||
$/ = $fs;
|
||||
|
||||
$df =~ s/\n[ \t]+/ /mg;
|
||||
my @df = split(/\n/, $df);
|
||||
for my $ln (@df) {
|
||||
my ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln);
|
||||
if ($fs =~ m|^/dev/|) {
|
||||
my $mount_t = $mount;
|
||||
$mount_t =~ s|/|_|g;
|
||||
open REPQUOTA, "@@@repquota@@@ $mount 2>/dev/null |" or die "cannot call @@@repquota@@@: $!";
|
||||
my $hpuxtime = '(?:NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))';
|
||||
my $linuxtime = '(?:none|\d+\:\d+|\d+days)';
|
||||
while (<REPQUOTA>) {
|
||||
next unless (/\b\d+\b/); # ignore header lines
|
||||
my ($user, $msg) = parseline($mount, $_);
|
||||
if ($msg) {
|
||||
my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user$mount_t";
|
||||
|
||||
|
@ -170,17 +184,14 @@ for my $ln (@df) {
|
|||
print PMSG (@time);
|
||||
close (PMSG);
|
||||
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
my $comp = -A $timestamp;
|
||||
print STDERR "comp = $comp\n";
|
||||
if ($comp > 5)
|
||||
{
|
||||
if ($comp > 5) {
|
||||
sendmail($user, $msg, $mount);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user$mount_t");
|
||||
unlink (@deletemsg);
|
||||
}
|
||||
|
@ -188,3 +199,14 @@ for my $ln (@df) {
|
|||
close (REPQUOTA);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub selftest {
|
||||
my $rc = 0;
|
||||
my ($user, $msg);
|
||||
|
||||
($user, $msg) = parseline("test", "haas +- 1348620 1048576 2097152 41:48 296 3000 6000\n");
|
||||
unless ($user eq "haas" && $msg) {$rc = 1};
|
||||
|
||||
exit($rc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue