File:  [LON-CAPA] / loncom / debugging_tools / login_count.pl
Revision 1.1: download - view: text, annotated - select for diffs
Fri Sep 3 19:51:58 2004 UTC (19 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- count the number of login from a certain date

    1: use File::Find;
    2: use POSIX qw(strftime);
    3: use lib '/home/httpd/lib/perl/';
    4: use LONCAPA::Configuration;
    5: use Date::Manip;
    6: my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
    7: $|=1;
    8: find(
    9:          {
   10: #          preprocess => \&only_user_activitylog_files,
   11: #          wanted     => \&print_filename,
   12: #          wanted     => \&log_metadata,
   13:           wanted     => \&process_activitylog_file,
   14:           }, 
   15:          $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
   16: &print_data();
   17: sub only_user_activitylog_files {
   18:     print (join("\n",@_));
   19:     return 1;
   20: }
   21: 
   22: my $start_time=&UnixDate("Aug 30th 00:00:00 2004","%s");
   23: my %data;
   24: my $numusers;
   25: sub process_activitylog_file {
   26:     if ($File::Find::dir=~m|/\d/\d/\d/|) { return; }
   27:     if ($_ ne 'activity.log') {	return; }
   28:     open(FILE,"<$File::Find::name");
   29:     $numusers++;
   30:     my $user=(split('/',$File::Find::dir))[-1];
   31:     while (my $line=<FILE>) {
   32: 	if ($line !~ /Login/) { next; }
   33: 	my ($date)=split(':',$line,2);
   34: 	if ($date > 1093838400) { push (@{$data{$date}},$user);	}
   35:     }
   36:     if ($numusers%100 == 0) {
   37: 	print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
   38:     }
   39: }
   40: sub print_data {
   41:     my $total_login=0;
   42:     my %byday;
   43:     print("\n");
   44:     foreach my $key (sort(keys(%data))) {
   45: 	#print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
   46: 	$total_login+=scalar(@{$data{$key}});
   47: 	my $day=strftime('%F',localtime($key));
   48: 	$byday{$day}+=scalar(@{$data{$key}});
   49:     }
   50:     foreach my $key (sort(keys(%byday))) {
   51:     	print("$key -> $byday{$key}\n");
   52:     }
   53:     print("total -> $total_login\n");
   54: }
   55: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>