> There is a utility out there, but I can't find it either. Anyone else know > where to look?
What follows is a Perl script that accomplishes this. It is also available at: ftp://not.tdlc.com/pub/checkimail.pl Modify to fit your situation. #!/usr/bin/perl #--------------------------------------------------------------------- # thomas kishel: 12-04-2001 #--------------------------------------------------------------------- use Mail::Sendmail; use strict; #--------------------------------------------------------------------- # begin configuration #--------------------------------------------------------------------- my ($path, $host, $limit, $maximum); # path to user mailboxes $path = q|c:/imail/users|; # host name of mailboxes $host = q|your.domain.name|; # mailbox warning limit in megabytes $limit = 20; # mailbox maximum in megabytes $maximum = 25; #--------------------------------------------------------------------- # end configuration #--------------------------------------------------------------------- &CheckDiskSpace($path, $host, $maximum, $limit); 1; #--------------------------------------------------------------------- # CheckDiskSpace #--------------------------------------------------------------------- sub CheckDiskSpace { my ($source_path, $host, $maximum, $limit) = @_; my (@user_list, $user, $size); # convert warning limit to bytes $limit = $limit * 1024 * 1024; # get a list of directories opendir (DIR_HANDLE, $source_path) || die; @user_list = readdir (DIR_HANDLE); closedir (DIR_HANDLE) || die; # review each directory foreach $user (@user_list) { next if ($user eq '.' || $user eq '..'); $path = qq|$source_path/$user|; next if (! -d ($path)); $size = &CalculateDiskSpace($path); if ($size > $limit) { &Notify($user, $host, $maximum, $size); } } return 1; } #--------------------------------------------------------------------- # CalculateDiskSpace #--------------------------------------------------------------------- sub CalculateDiskSpace { my ($source_path) = @_; my (@directory_list, $item, $directory, @file_list, $file, $size); # initialize variables push (@directory_list, '.'); $size = 0; # get a recursive list of directories &GetDirectories(\$source_path, '', \@directory_list); # review each file in each directory in the directory structure foreach $item (@directory_list) { $directory = qq|$source_path/$item|; opendir (DIR_HANDLE, $directory) || die; @file_list = readdir (DIR_HANDLE); closedir (DIR_HANDLE) || die; foreach $file (@file_list) { next if ($file eq '.' || $file eq '..'); $file = "$directory/$file"; next if (-d ($file)); $size = $size + (-s ($file)); } } return $size; } #-------------------------------------------------------------------- # GetDirectories # # note: this subroutine is recursive #-------------------------------------------------------------------- sub GetDirectories { my ($root_directory, $directory, $directory_list) = @_; my (@list, $item, $this_full_directory, $this_directory); if ($directory) { $this_full_directory = qq|$$root_directory/$directory|; } else { $this_full_directory = $$root_directory; } opendir (DIR_HANDLE, $this_full_directory) || die ($this_full_directory); @list = readdir(DIR_HANDLE); closedir (DIR_HANDLE) || die; foreach $item (@list) { next if ($item eq '.' || $item eq '..'); if ($directory) { $this_full_directory = qq|$$root_directory/$directory/$item|; $this_directory = qq|$directory/$item|; } else { $this_full_directory = qq|$$root_directory/$item|; $this_directory = $item; } next if (! -d $this_full_directory); push (@$directory_list, $this_directory); &GetDirectories ($root_directory, $this_directory, $directory_list); } return 1; } #--------------------------------------------------------------------- # Notify #--------------------------------------------------------------------- sub Notify { my ($user, $host, $maximum, $size) = @_; my ($from, $to, $subject, $message); $user = lc($user); $size = int($size / 1024 / 1024); $from = qq|postmaster\@$host|; $to = qq|$user\@$host|; $subject = qq|Email Account Status|; $message = qq|$to\n\n|; $message .= qq|Your email account is using $size MB of disk space on the server.\nThe limit is $maximum MB.\n\nIf you exceed this limit, any new messages will be returned to the sender as undeliverable.\n\n|; $message .= qq|Please purge your mailboxes of unnecessary messages to prevent the system from automatically (but arbitrarily) correcting the problem by deleting your oldest messages.\n\n|; # send to the user &Mail::Sendmail::send_mail ($from, $user\@$host, $subject, $message); # send a copy to the administrator &Mail::Sendmail::send_mail ($from, $from, $subject, $message); # debugging utility #print qq|$message\n|; return 1; } Please visit http://www.ipswitch.com/support/mailing-lists.html to be removed from this list. An Archive of this list is available at: http://www.mail-archive.com/imail_forum%40list.ipswitch.com/
