Fixed some more parsing problems. Added beginning of a test suite.

This commit is contained in:
hjp 2005-03-29 09:53:12 +00:00
parent b7acf57799
commit 71d8515467
1 changed files with 66 additions and 44 deletions

View File

@ -88,30 +88,12 @@ sub sendmail
print SENDMAIL "$msg\r\n"; print SENDMAIL "$msg\r\n";
} }
getopts('ad', \%opts); sub parseline($$) {
my ($mount, $line) = @_;
$hostname=`hostname`; local $_ = $line;
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 $hpuxtime = '(?:NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))';
my $linuxtime = '(?:none|\d+\:\d+|\d+days)'; my $linuxtime = '(?:none|\d+\:\d+|\d+days)';
while (<REPQUOTA>) { return undef unless (/\b\d+\b/); # ignore header lines
next unless (/\b\d+\b/); # ignore header lines
my $msg = ""; my $msg = "";
my $user; my $user;
if (/(\w+) \s+ -- \s* if (/(\w+) \s+ -- \s*
@ -148,6 +130,38 @@ for my $ln (@df) {
print "$mount: $.: unparseable: $_"; print "$mount: $.: unparseable: $_";
next; 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) { if ($msg) {
my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user$mount_t"; my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user$mount_t";
@ -170,17 +184,14 @@ for my $ln (@df) {
print PMSG (@time); print PMSG (@time);
close (PMSG); close (PMSG);
} } else {
else{
my $comp = -A $timestamp; my $comp = -A $timestamp;
print STDERR "comp = $comp\n"; print STDERR "comp = $comp\n";
if ($comp > 5) if ($comp > 5) {
{
sendmail($user, $msg, $mount); sendmail($user, $msg, $mount);
} }
} }
} } else{
else{
my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user$mount_t"); my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user$mount_t");
unlink (@deletemsg); unlink (@deletemsg);
} }
@ -188,3 +199,14 @@ for my $ln (@df) {
close (REPQUOTA); 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);
}