Thanks for the alternate method. My method was crude, but works on my server
at work as well as at home. Maybe this will fix some of the problems. I
believe the reliance on DIR to retrieve this info is the reason many users
are getting errors.

Here is the new dir_list routine modified slightly to replace the old one:

###########################################################################
# Subroutine contributed by David Gregg [EMAIL PROTECTED] to return a list
of subdirectories.
###########################################################################

sub dir_list {
local($l_physicaldirectory) = @_;
local(@l_alldirs, $l_dir);
chdir("$l_physicaldirectory");
opendir(THISDIR, ".");
@l_alldirs = grep(-d, grep(!/^\.\.?$/ , readdir(THISDIR)));
closedir(THISDIR);
@l_alldirs = sort(@l_alldirs);
return @l_alldirs;
}

Not tested, but should work as is. I'll try to implement these into the
script tonight. Very nice routine. Thanks for the contribution. Stick with
it and maybe we can get the bugs out.

> -----Original Message-----
> From: David Gregg [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, April 27, 2000 12:50 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: [IMail Forum] issue warnings to users approaching the
> mailboxsize limit
> 
> Forgive the multiple posts, but I forgot to include the snippet for
> returning a list of subdirs.
> 
> Thanks again for your contribution to the list Joel!
> 
> &dodirlist('c:\imail');
> exit;
> 
> sub dodirlist {
>  local($l_physicaldirectory) = @_;
>  local(@l_alldirs, $l_dir);
>  chdir("$l_physicaldirectory");
>  opendir(THISDIR, ".");
>  @l_alldirs = grep(-d, grep(!/^\.\.?$/ , readdir(THISDIR)));
>  closedir(THISDIR);
> 
>  @l_alldirs = sort(@l_alldirs);
> 
>  foreach $l_dir (@l_alldirs) {
>   print "$l_dir\n";
> 
> }
> }
> 
> -----Original Message-----
> From: David Gregg <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Thursday, April 27, 2000 8:59 AM
> Subject: Re: [IMail Forum] issue warnings to users approaching the
> mailboxsize limit
> 
> 
> >The attached file will calculate total kbytes of a dir using only perl...
> >
> >
> >-----Original Message-----
> >From: Joel Morgan <[EMAIL PROTECTED]>
> >To: '[EMAIL PROTECTED]' <[EMAIL PROTECTED]>
> >Date: Thursday, April 27, 2000 8:03 AM
> >Subject: RE: [IMail Forum] issue warnings to users approaching the
> >mailboxsize limit
> >
> >
> >>I haven't tested the script on Windows 2000 yet. The script relies
> heavily
> >>on the DIR command to get a list of mailboxes as well as the size. If
> >>Windows 2000 does this any differently than NT4 it will break. Will you
> >>verify this for me?
> >>
> >>When you issue the command "dir /ad C:\imail\users" what do you get? Can
> >you
> >>redirect it "> test.txt" and send it to me?
> >>
> >>For example on NT4 SP5, when the script issues the command to get a list
> of
> >>home directories:
> >>@lines = `dir /ad "$test_dir"`;
> >>
> >>which on my system is equivalent to "dir /ad E:\imail\users"
> >>
> >>It gets:
> >>
> >> Volume in drive E has no label.
> >> Volume Serial Number is 548A-792A
> >>
> >> Directory of e:\imail\users
> >>
> >>04/27/00  08:02a        <DIR>          .
> >>04/27/00  08:02a        <DIR>          ..
> >>03/01/00  03:07p        <DIR>          aacos1
> >>03/01/00  03:55p        <DIR>          aagui1
> >>03/01/00  03:39p        <DIR>          aalfo1
> >>03/01/00  03:07p        <DIR>          aalle1
> >><SNIP>
> >>03/01/00  03:08p        <DIR>          zluca1
> >>04/25/00  02:17p        <DIR>          zpers1
> >>03/01/00  03:08p        <DIR>          ztayl1
> >>03/01/00  03:52p        <DIR>          zthom1
> >>03/01/00  03:20p        <DIR>          zveal1
> >>03/01/00  03:58p        <DIR>          zwaji1
> >>            3755 File(s)              0 bytes
> >>                         91,578,900,480 bytes free
> >>
> >>The script removes everything but lines containing directory listings:
> >>#Remove first 7 lines, and last 2 lines
> >>pop(@lines);
> >>pop(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>shift(@lines);
> >>
> >>It then isolates the user directories and builds a hash of directory
> >>listings only:
> >>#Loop through each line of directory output and strip out everything
> >>#but the directory then call dir_size.
> >>#assign @lines to $line, one at a time
> >>foreach $line (@lines)
> >> {
> >> @line = split(/ /,$line,21);
> >> splice(@line,0,20);
> >> chomp(@line);
> >> my $current_dir = $line[0];
> >> push (@list, $current_dir);
> >> }
> >>
> >>It returns a hash containing all user directories:
> >>return @list;
> >>
> >>When you issue the command "dir /s/w C:\imail\users\USERNAME\*.mbx" what
> do
> >>you get? Can you redirect it "> test2.txt" and send it to me?
> >>
> >>For example on NT4 SP5, when the script issues the command to get total
> >>mailbox size:
> >>@res = `dir /s/w "$test_dir"`;
> >>
> >>which on my system is equivalent to "dir /s/w
> e:\imail\users\jmorgan\*.mbx"
> >>
> >>I get:
> >>
> >> Volume in drive E has no label.
> >> Volume Serial Number is 548A-792A
> >>
> >>
> >> Directory of e:\imail\users\jmorgan
> >>
> >>Main.mbx
> >>               1 File(s)         11,203 bytes
> >>
> >>     Total Files Listed:
> >>               1 File(s)         11,203 bytes
> >>                         91,579,039,744 bytes free
> >>
> >>In the script I take this and extract the line with the size in it:
> >># The second to last line has the number of files and
> >># total size of the the directory
> >>my $LastLine = $res[-2];
> >>
> >>I then Isolate the number with:
> >>@res = split(/ /,$LastLine);
> >>
> >>Remove the commas:
> >>$_ = $res[-2];
> >>tr/0-9//cd;
> >>$res[-2] = $_;
> >>
> >>And return the total size of all mbx files:
> >>return $res[-2];
> >>
> >>As you can see, any variance in the way DIR prints its results may break
> >the
> >>script. I don't have a Windows 2000 system running right now, so I can't
> >>verify the output of the DIR command on Windows 2000.
> >>
> >>Hopefully I can make some changes and get it to work for everyone, once
> I
> >>get enough feedback. Any Perl gurus know a better way?
> >>
> >>> -----Original Message-----
> >>> From: Dave Koontz [SMTP:[EMAIL PROTECTED]]
> >>> Sent: Wednesday, April 26, 2000 8:43 PM
> >>> To: "Joel Morgan"
> >>> Subject: Re: [IMail Forum] issue warnings to users approaching the
> >>> mailbox size limit
> >>>
> >>> First I would just like to say THANKS for providing such a nice script
> >for
> >>> everyone's use!
> >>>
> >>> I agree with another user on the iMail list that their should be TWO
> >>> levels
> >>> of notifications,  perhaps at 75% - polite, and another more serious
> one
> >>> at
> >>> 90%....
> >>>
> >>> Now, I do have a problem with the current script.  Perhaps I am just
> to
> >>> naive with perl.  I am running iMail v6.03 on NT 2000.  When I run
> your
> >>> script, it displays "NO USER" name.... further it appears that it is
> just
> >>> looking at the \imail\users folder and not the individual user's
> folder
> >as
> >>> the bytes for each user it finds are identical.  When I modify your
> >script
> >>> and attempt to isolate the $dir variable --- it returns "" (nothing)
> So
> >>> the
> >>> registry key and the User folder your script looks at is always the
> root
> >>> of
> >>> both.   Can you help a newbie?  <g>
> >>>
> >>> Thanks again....
> >>>
> >>> ----- Original Message -----
> >>> From
> >>> To: <[EMAIL PROTECTED]>
> >>> Sent: Wednesday, April 26, 2000 4:35 PM
> >>> Subject: [IMail Forum] issue warnings to users approaching the mailbox
> >>> size
> >>> limit
> >>>
> >>>
> >>> Imail version 6.X lacks the ability to issue warnings to users
> >approaching
> >>> the mailbox size limit. This perl script scans the registry for each
> >>> domain
> >>> and checks each user's mailbox size against MaxSize entered for the
> user
> >>> in
> >>> the registry. If the user has 0 entered as MaxSize then the domains
> >>> MaxSize
> >>> entry is used. If the mailbox is within 10% of the limit it emails a
> >>> caution
> >>> to the user and logs it. If the user's mailbox exceeds the limit it
> only
> >>> logs it. The resulting log file is then emailed to the postmaster
> >account.
> >>> Sizes are reported in bytes.
> >>>
> >>> To run the script every 24 hours, schedule with the command "AT 2:00
> >>> /interactive /every:Su,M,T,W,Th,F,S C:\BIN\LIMIT.PL"
> >>>
> >>> I would appreciate any comments or suggestions. For example should the
> >>> user
> >>> continue to be warned once the mailbox limit has been passed. Maybe
> even
> >>> warn until the user is 10% over the limit. It currently starts warning
> >the
> >>> user at 10% of the limit and continues until the limit is reached. I
> >don't
> >>> want the number of warnings mailed to a user to be infinite.
> >>>
> >>> It should work without any configuration settings other than to either
> >>> manually run it or schedule it. Would someone give it a shot and help
> me
> >>> test it?
> >>>
> >>> It seems to work fine, but use at your own risk!
> >>>
> >>> Works with Activestate's Perl available at http://www.activestate.com/
> >>>
> >>>  <<LIMIT.PL>>
> >>>
> >>Please visit http://www.ipswitch.com/support/mailing-lists.html
> >>to be removed from this list.
> >>
> >
> 
> Please visit http://www.ipswitch.com/support/mailing-lists.html 
> to be removed from this list.
Please visit http://www.ipswitch.com/support/mailing-lists.html 
to be removed from this list.

Reply via email to