From 8c77a4c68bebf1bb0bd2b5bddf2aab22b82bd9c8 Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 18 May 1998 14:54:02 +0000 Subject: [PATCH] quotacheck: prerelease in production quotastat: Should work --- quotacheck/.vimrc | 4 ++ quotacheck/GNUmakefile | 28 +++++++++++++ quotacheck/quotacheck.pl | 87 ++++++++++++++++++++++++++++++++++++++++ quotacheck/quotastat.pl | 40 ++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 quotacheck/.vimrc create mode 100644 quotacheck/GNUmakefile create mode 100644 quotacheck/quotacheck.pl create mode 100644 quotacheck/quotastat.pl diff --git a/quotacheck/.vimrc b/quotacheck/.vimrc new file mode 100644 index 0000000..60aa1bd --- /dev/null +++ b/quotacheck/.vimrc @@ -0,0 +1,4 @@ +set autoindent +set autowrite +set exrc +set shiftwidth=4 diff --git a/quotacheck/GNUmakefile b/quotacheck/GNUmakefile new file mode 100644 index 0000000..53c130d --- /dev/null +++ b/quotacheck/GNUmakefile @@ -0,0 +1,28 @@ +include GNUmakevars +BINDIR=/usr/local/sbin + +all: quotacheck quotastat + +clean: + rm -f quotacheck *.bak + +distclean: clean + rm -f customize + +install: $(BINDIR) $(BINDIR)/quotacheck $(BINDIR)/quotastat + +%: %.pl customize + sh ./customize < $< > $@ + chmod +x $@ + +%: %.sh customize + sh ./customize < $< > $@ + chmod +x $@ + +customize: configure + sh ./configure + +$(BINDIR): + mkdir -p $@ + +include GNUmakerules diff --git a/quotacheck/quotacheck.pl b/quotacheck/quotacheck.pl new file mode 100644 index 0000000..8961ae2 --- /dev/null +++ b/quotacheck/quotacheck.pl @@ -0,0 +1,87 @@ +#!@@@perl@@@ + +sub warnmsg { + my ($mount, $usage, $soft, $hard, $grace, $unit) = @_; + + my $msg = "Sie haben auf $mount (Host $hostname) Ihr Limit von $soft $unit " . + "um " . ($usage - $soft) . " $unit überschritten.\n"; + + if ($grace eq "EXPIRED" or $usage >= $hard-2) { + $msg .= "Sie können dort KEINE Files mehr anlegen.\n" . + "Bitte löschen Sie eine entsprechende Anzahl Files\n" . + "oder wenden Sie sich an einen Systemadministrator.\n"; + } else { + $grace =~ s/days/Tage/g; + $grace =~ s/hours/Stunden/g; + $msg .= "Sie können dieses Limit noch $grace um maximal " . + ($hard - $soft) . " $unit überschreiten.\n" . + "Sollte das nicht reichen, wenden Sie sich an einen Systemadministrator.\n"; + } + return $msg; +} + + +$hostname=`hostname`; +chomp($hostname); +open (DF, "@@@df@@@ |") or die "cannot call @@@df@@@: $!"; + +$fs = $/; +undef ($/); +$df = ; +close(DF); +$/ = $fs; + +$df =~ s/\n[ \t]+/ /mg; +@df = split(/\n/, $df); +for $ln (@df) { + ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln); + if ($fs =~ m|^/dev/|) { + print $mount, "\n"; + open REPQUOTA, "@@@repquota@@@ $mount |" or die "cannot call @@@repquota@@@: $!"; + while () { + $msg = ""; + if (/(\w+) \s+ -- \s* + (\d+)\s+(\d+)\s+(\d+)\s+ + (\d+)\s+(\d+)\s+(\d+) + /x) { + #print "ok: $1\n"; + } elsif (/(\w+) \s+ \+- \s* + (\d+)\s+(\d+)\s+(\d+)\s+(EXPIRED|\d+\.\d+\ (?:days|hours))\s+ + (\d+)\s+(\d+)\s+(\d+) + /x) { + print "block limit: $1: $2 > ($3 $4) $5\n"; + $user = $1; + $msg = warnmsg($mount, $2, $3, $4, $5, "kB"); + + } elsif (/(\w+) \s+ -\+ \s* + (\d+)\s+(\d+)\s+(\d+)\s+ + (\d+)\s+(\d+)\s+(\d+)\s+(EXPIRED|\d+\.\d+\ (?:days|hours)) + /x) { + print "file limit: $1: $5 > ($6 $7) $8\n"; + $user = $1; + $msg = warnmsg($mount, $5, $6, $7, $8, "Files"); + } elsif (/(\w+) \s+ \+\+ \s* + (\d+)\s+(\d+)\s+(\d+)\s+(EXPIRED|\d+\.\d+\ (?:days|hours))\s+ + (\d+)\s+(\d+)\s+(\d+)\s+(EXPIRED|\d+\.\d+\ (?:days|hours)) + /x) { + print "block limit: $1: $2 > ($3 $4) $5\n"; + $user = $1; + $msg = warnmsg($mount, $2, $3, $4, $5, "kB"); + print "file limit: $1: $6 > ($7 $8) $9\n"; + $msg .= "\n\n" . warnmsg($mount, $6, $7, $8, $9, "Files"); + } else { + print "unparseable: $_"; + } + if ($msg) { + open (SENDMAIL, "|@@@sendmail@@@ -t -i"); + print SENDMAIL "To: <$user\@wsr.ac.at>\r\n"; + print SENDMAIL "Cc: \r\n"; + print SENDMAIL "Reply-To: \r\n"; + print SENDMAIL "Subject: Disk Quotas überschritten\r\n"; + print SENDMAIL "\r\n"; + print SENDMAIL "$msg\r\n"; + } + + } + } +} diff --git a/quotacheck/quotastat.pl b/quotacheck/quotastat.pl new file mode 100644 index 0000000..b408206 --- /dev/null +++ b/quotacheck/quotastat.pl @@ -0,0 +1,40 @@ +#!@@@perl@@@ + +$hostname=`hostname`; +chomp($hostname); +$date=`date '+%Y-%m-%dT%H:%M:%S'`; +chomp($date); +open (DF, "@@@df@@@ |") or die "cannot call @@@df@@@: $!"; + +$fs = $/; +undef ($/); +$df = ; +close(DF); +$/ = $fs; + +$df =~ s/\n[ \t]+/ /mg; +@df = split(/\n/, $df); + +open (STAT, ">>/usr/local/dfstat/quota.stat") or die "cannot append to quota.stat"; +for $ln (@df) { + ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln); + if ($fs =~ m|^/dev/|) { + print $mount, "\n"; + open REPQUOTA, "@@@repquota@@@ $mount |" or die "cannot call @@@repquota@@@: $!"; + while () { + $msg = ""; + if (/^\s+/) { + #print "header: $_"; + } elsif (/(\w+) \s+ [-+][-+] \s* + (\d+)\s+(\d+)\s+(\d+)\s+(|EXPIRED|\d+\.\d+\ (?:days|hours))\s+ + (\d+)\s+(\d+)\s+(\d+)\s+(|EXPIRED|\d+\.\d+\ (?:days|hours)) + /x) { + print "block limit: $1: $2 > ($3 $4) $5\n"; + print "file limit: $1: $6 > ($7 $8) $9\n"; + print STAT "$date\t$mount\t$1\t$2\t$3\t$4\t$6\t$7\t$8\n"; + } else { + print "unparseable: $_"; + } + } + } +}