2001-08-13 17:25:55 +02:00
|
|
|
|
#!@@@perl@@@ -w
|
|
|
|
|
|
|
|
|
|
use strict;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
|
1998-09-17 09:30:12 +02:00
|
|
|
|
use Getopt::Std;
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $time=time;
|
|
|
|
|
my @time=localtime($time);
|
|
|
|
|
my $hostname;
|
1998-09-17 09:30:12 +02:00
|
|
|
|
|
1998-05-18 16:54:02 +02:00
|
|
|
|
sub warnmsg {
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my ($mount, $usage, $soft, $hard, $grace, $unit, $user) = @_;
|
|
|
|
|
my %dosdrv = (
|
1998-09-17 09:30:12 +02:00
|
|
|
|
'/wifosv/dosprogs' => 'H:',
|
|
|
|
|
'/wsrdb/users' => 'J:',
|
|
|
|
|
'/wifosv/users' => 'K:',
|
|
|
|
|
'/usr/local/www' => 'W:',
|
|
|
|
|
);
|
|
|
|
|
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $wo;
|
1998-09-17 09:30:12 +02:00
|
|
|
|
if ($dosdrv{$mount}) {
|
|
|
|
|
$wo = 'Netzplatte ' . $dosdrv{$mount};
|
|
|
|
|
} else {
|
|
|
|
|
$wo = "$mount (Host $hostname)";
|
|
|
|
|
}
|
1998-05-18 16:54:02 +02:00
|
|
|
|
|
1999-07-09 20:06:17 +02:00
|
|
|
|
|
1998-09-17 09:30:12 +02:00
|
|
|
|
my $msg = "Sie haben auf $wo Ihr in Disk Quotas gesetztes Limit\n" .
|
2001-08-13 17:25:55 +02:00
|
|
|
|
"<22>berschritten. \n";
|
|
|
|
|
|
1998-05-18 16:54:02 +02:00
|
|
|
|
if ($grace eq "EXPIRED" or $usage >= $hard-2) {
|
1998-09-17 09:30:12 +02:00
|
|
|
|
$msg .= "Sie k<>nnen dort KEINE Files mehr anlegen.\n" ;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
} else {
|
|
|
|
|
$grace =~ s/days/Tage/g;
|
|
|
|
|
$grace =~ s/hours/Stunden/g;
|
1998-09-17 09:30:12 +02:00
|
|
|
|
$msg .= "Sie k<>nnen noch " .
|
1999-07-09 20:06:17 +02:00
|
|
|
|
(int (($hard - $usage) * 10 + 0.5) / 10) . " $unit anlegen.\n" ;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
}
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $mount_t = $mount;
|
|
|
|
|
$mount_t =~ s|/|_|g;
|
|
|
|
|
|
1998-09-17 09:30:12 +02:00
|
|
|
|
$msg .= "\nBei dringendem Bedarf k<>nnen Sie sofort zus<75>tzlichen Platz schaffen,\n" .
|
|
|
|
|
"indem Sie auf $wo Files l<>schen, komprimieren oder auf eine\n" .
|
|
|
|
|
"andere Netzplatte verschieben.\n" .
|
|
|
|
|
"\n" .
|
2001-08-13 17:25:55 +02:00
|
|
|
|
"Sie k<>nnen sich Ihre Verbrauchsgraphen unter\n" .
|
|
|
|
|
"http://sww.wsr.ac.at/intranet/quotas/$user$mount_t.gif ansehen. \n" .
|
|
|
|
|
"Die Quotas die Sie verwendet haben werden rot angezeigt. Au<41>erdem zeigen\n" .
|
|
|
|
|
"die Softquotas, die Grenze an, die Sie <20>berschritten haben und die Hardquotas\n" .
|
|
|
|
|
"die Obergrenze, die Sie nicht <20>berschreiten k<>nnen. \n" .
|
|
|
|
|
"\n" .
|
1998-09-17 09:30:12 +02:00
|
|
|
|
"Lassen Sie sich bei Gelegenheit auch von einem der zust<73>ndigen\n" .
|
|
|
|
|
"Systemadministratoren unterst<73>tzen:\n" .
|
|
|
|
|
"Peter Holzer, hjp\@wsr.ac.at, Kl. 786\n" .
|
|
|
|
|
"Michael Demelbauer, michael\@wsr.ac.at, Kl. 787\n";
|
1998-05-18 16:54:02 +02:00
|
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my %opts;
|
|
|
|
|
|
|
|
|
|
sub sendmail
|
|
|
|
|
{
|
|
|
|
|
my ($user, $msg, $mount) = @_;
|
|
|
|
|
|
|
|
|
|
my @startgraph=
|
|
|
|
|
("/usr/local/dfstat/quotagraph",
|
|
|
|
|
"--fs=$mount",
|
|
|
|
|
"--user=$user",
|
|
|
|
|
"--data=b",
|
|
|
|
|
glob("/usr/local/dfstat/quota.stat.????-??")
|
|
|
|
|
);
|
|
|
|
|
if (system (@startgraph) != 0) {
|
|
|
|
|
die "cannot execute @startgraph";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($opts{'d'}) {
|
|
|
|
|
open (SENDMAIL, ">&1");
|
|
|
|
|
} else {
|
|
|
|
|
open (SENDMAIL, "|@@@sendmail@@@ -t -i");
|
|
|
|
|
}
|
|
|
|
|
if ($opts{'a'}) {
|
|
|
|
|
print SENDMAIL "To: <system\@wsr.ac.at>\r\n";
|
|
|
|
|
print SENDMAIL "Subject: User $user: Disk Quotas <20>berschritten\r\n";
|
|
|
|
|
} else {
|
|
|
|
|
print SENDMAIL "To: <$user\@wsr.ac.at>\r\n";
|
|
|
|
|
print SENDMAIL "Cc: <system\@wsr.ac.at>\r\n";
|
|
|
|
|
print SENDMAIL "Subject: Disk Quotas <20>berschritten\r\n";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
print SENDMAIL "Reply-To: <system\@wsr.ac.at>\r\n";
|
|
|
|
|
print SENDMAIL "\r\n";
|
|
|
|
|
print SENDMAIL "$msg\r\n";
|
|
|
|
|
}
|
|
|
|
|
|
1998-09-17 09:30:12 +02:00
|
|
|
|
getopts('ad', \%opts);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
|
|
|
|
|
$hostname=`hostname`;
|
|
|
|
|
chomp($hostname);
|
|
|
|
|
open (DF, "@@@df@@@ |") or die "cannot call @@@df@@@: $!";
|
|
|
|
|
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $fs = $/;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
undef ($/);
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $df = <DF>;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
close(DF);
|
|
|
|
|
$/ = $fs;
|
|
|
|
|
|
|
|
|
|
$df =~ s/\n[ \t]+/ /mg;
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my @df = split(/\n/, $df);
|
|
|
|
|
for my $ln (@df) {
|
|
|
|
|
my ($fs, $total, $used, $free, $pct, $mount) = split(/\s+/, $ln);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
if ($fs =~ m|^/dev/|) {
|
1998-09-17 09:30:12 +02:00
|
|
|
|
open REPQUOTA, "@@@repquota@@@ $mount 2>/dev/null |" or die "cannot call @@@repquota@@@: $!";
|
1998-05-18 16:54:02 +02:00
|
|
|
|
while (<REPQUOTA>) {
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $msg = "";
|
|
|
|
|
my $user;
|
1998-05-18 16:54:02 +02:00
|
|
|
|
if (/(\w+) \s+ -- \s*
|
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+
|
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)
|
|
|
|
|
/x) {
|
|
|
|
|
#print "ok: $1\n";
|
|
|
|
|
} elsif (/(\w+) \s+ \+- \s*
|
1998-09-17 09:30:12 +02:00
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))\s+
|
1998-05-18 16:54:02 +02:00
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)
|
|
|
|
|
/x) {
|
|
|
|
|
print "block limit: $1: $2 > ($3 $4) $5\n";
|
|
|
|
|
$user = $1;
|
2001-08-13 17:25:55 +02:00
|
|
|
|
$msg = warnmsg($mount, $2/1024, $3/1024, $4/1024, $5, "MB", $user);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
|
|
|
|
|
} elsif (/(\w+) \s+ -\+ \s*
|
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+
|
1998-09-17 09:30:12 +02:00
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))
|
1998-05-18 16:54:02 +02:00
|
|
|
|
/x) {
|
|
|
|
|
print "file limit: $1: $5 > ($6 $7) $8\n";
|
|
|
|
|
$user = $1;
|
2001-08-13 17:25:55 +02:00
|
|
|
|
$msg = warnmsg($mount, $5, $6, $7, $8, "Files", $user);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
} elsif (/(\w+) \s+ \+\+ \s*
|
1998-09-17 09:30:12 +02:00
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))\s+
|
|
|
|
|
(\d+)\s+(\d+)\s+(\d+)\s+(NOT\sSTARTED|EXPIRED|\d+\.\d+\ (?:days|hours))
|
1998-05-18 16:54:02 +02:00
|
|
|
|
/x) {
|
|
|
|
|
print "block limit: $1: $2 > ($3 $4) $5\n";
|
|
|
|
|
$user = $1;
|
2001-08-13 17:25:55 +02:00
|
|
|
|
$msg = warnmsg($mount, $2/1024, $3/1024, $4/1024, $5, "MB", $user);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
print "file limit: $1: $6 > ($7 $8) $9\n";
|
2001-08-13 17:25:55 +02:00
|
|
|
|
$msg .= "\n\n" . warnmsg($mount, $6, $7, $8, $9, "Files", $user);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
} else {
|
1998-09-17 09:30:12 +02:00
|
|
|
|
if ($. > 2) { # ignore header lines
|
|
|
|
|
print "$mount: $.: unparseable: $_";
|
|
|
|
|
}
|
1998-05-18 16:54:02 +02:00
|
|
|
|
}
|
|
|
|
|
if ($msg) {
|
2001-08-13 17:25:55 +02:00
|
|
|
|
my $timestamp = "/usr/local/dfstat/quotacheck-timestamps/$user";
|
|
|
|
|
|
|
|
|
|
if (!-e $timestamp) {
|
|
|
|
|
sendmail($user, $msg, $mount);
|
|
|
|
|
open (PMSG, ">$timestamp")
|
|
|
|
|
or die "cannot open $timestamp: $!";
|
|
|
|
|
print PMSG (@time);
|
|
|
|
|
close (PMSG);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
my $comp = -A $timestamp;
|
|
|
|
|
print STDERR "comp = $comp\n";
|
|
|
|
|
if ($comp > 5)
|
|
|
|
|
{
|
|
|
|
|
sendmail($user, $msg, $mount);
|
|
|
|
|
}
|
1998-09-17 09:30:12 +02:00
|
|
|
|
}
|
1998-05-18 16:54:02 +02:00
|
|
|
|
}
|
2001-08-13 17:25:55 +02:00
|
|
|
|
else{
|
|
|
|
|
my $user;
|
|
|
|
|
my @deletemsg = ("/usr/local/dfstat/quotacheck-timestamps/$user");
|
|
|
|
|
unlink (@deletemsg);
|
|
|
|
|
}
|
1998-05-18 16:54:02 +02:00
|
|
|
|
}
|
1998-09-17 09:30:12 +02:00
|
|
|
|
close (REPQUOTA);
|
1998-05-18 16:54:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|