#!/usr/bin/perl # # Send out e-mail warnings to those over their soft quota limit # use strict; use Net::SMTP; my $USER_START = 500; # everything under is not a user my $USER_END = 2000; # everything over is a machine my $from = "OTC Quota Manager "; my $subject = "Quota Warning"; # get a list of valid users open PASSWD, "/etc/passwd" or die "Unable to read /etc/passwd: $!\n"; my ($line, $pwent, @pwent); my %passwd; while (my $pwent = ) { chop $pwent; $pwent =~ s/\s+$//; $pwent = lc($pwent); my @pwent = split (/:/, $pwent); next if (($pwent[2] < $USER_START) || ($pwent[2] >= $USER_END)); $passwd{$pwent[0]} = 1; } close PASSWD; # get quota information open (REPQUOTA, "/usr/sbin/repquota /home/users |") or die "Unable to get repquota information! ($!)"; while (my $line = ) { chop $line; my @quota_info = split (/\s+/, $line); # (user, junk, used, soft limit, hard limit, grace, inode limits, ....) next unless ($passwd{$quota_info[0]}); # skip non-normal users next if (($quota_info[3] == 0) || ($quota_info[4] == 0)); if ($quota_info[2] >= $quota_info[3]) { printf "Sending a warning to [" . join (", ", @quota_info) . "]\n"; warn_user(@quota_info); } } close REPQUOTA; exit (0); sub warn_user { my @quota = @_; my $smtp = Net::SMTP->new('localhost'); $smtp->mail($from); $smtp->to("$quota[0]\@otc.isu.edu"); $smtp->data(); $smtp->datasend("From: $from\n"); $smtp->datasend("To: $quota[0] <$quota[0]\@otc.isu.edu>\n"); $smtp->datasend("Subject: $subject\n"); $quota[3] = $quota[3] / 1000; $quota[4] = $quota[4] / 1000; $quota[2] = $quota[2] / 1000; $smtp->datasend("\n"); $smtp->datasend("Warning: You have exceeded your quota on OTC's HOME (F:) drive.\n"); $smtp->datasend("\n"); $smtp->datasend("\tYour soft file limit = $quota[3] Mb\n"); $smtp->datasend("\tYour hard file limit = $quota[4] Mb\n"); $smtp->datasend("\tYour current usage = $quota[2] Mb\n"); $smtp->datasend("\n"); $smtp->datasend("Please remove any extraneous files, or have your quota limits changed.\n"); $smtp->datasend("\n"); $smtp->datasend("Here is a listing of your files and the space they are using:"); $smtp->datasend("\n"); my @du = `du -s ~$quota[0]/*`; foreach my $ent (@du) { $smtp->datasend($ent); } $smtp->datasend("\n"); $smtp->datasend(" -- OTC Quota Manager\n"); $smtp->datasend("\n"); $smtp->dataend(); $smtp->quit(); }