On 18 Feb 2005, [EMAIL PROTECTED] wrote:

> Is there a quick way (i.e., not scanning through the logs) to tell the
> last time an account has been accessed by the user, either by POP or
> IMAP?
> 
> We'd like to have a quick way to tell which accounts have been inactive
> for the past week/month/year etc. I've noticed that the dates of the
> dirs and files on the Maildir structure are modified when mails arrive
> or are read/deleted, etc. but I can't tell if some of them are only
> modified on reads... I think most of them are modified both on message
> arrivals (writes) and access (read), like the maildirsize file.

This certainly depends on your IMAP/POP server.  We use Courier
IMAP/POP and the logs go to the syslog; this is the script:

#!/usr/bin/perl -wn

# should be in the crontab with something similar to this:
# 0 2,6,10,14,18,22 * * * /usr/bin/note-active-system-users.pl /var/log/syslog

use strict;

our %users;				# because of -n we can't use 'my' here

if (m/user(name)?=(\w+)/)
{
 my $user = lc $2;
 my $maildir = "/var/qmail/maildirs/$user"; # set the maildir here
 # skip existing users
 next if exists $users{$user};
 # skip users without maildirs (e.g. wrong user name entered)
 next unless -d $maildir;
 system ('/bin/touch', "$maildir/active");
 $users{$user} = 1;
}
It basically looks for "user=xyz" and "username=xyz" in the logs and
creates /var/qmail/maildirs/xyz/active for each such user.  I'm sure
it's easy to adapt this to any other IMAP or POP server that logs to a
file.

Ted

Reply via email to