1: use strict;
2: use File::Find;
3: use POSIX qw(strftime);
4: use lib '/home/httpd/lib/perl/';
5: use LONCAPA::Configuration;
6: use Date::Manip;
7:
8: my $start_time=&UnixDate("Aug 30th 00:00:00 2004","%s");
9: my @counts=('1','10','100','1000','10000','100000','250000','1000000');
10: my @ignored_users=('^itds\d+$');
11:
12: sub only_user_activitylog_files {
13: print (join("\n",@_));
14: return 1;
15: }
16:
17: my %data;
18: my $numusers;
19: my %machine;
20: sub process_activitylog_file {
21: if ($File::Find::dir=~m|/\d/\d/\d/|) { return; }
22: if ($_ ne 'activity.log') { return; }
23: open(FILE,"<$File::Find::name");
24: $numusers++;
25: my $user=(split('/',$File::Find::dir))[-1];
26: foreach my $expr (@ignored_users) {
27: if ($user=~/$expr/) { print("\nignoring $user\n"); return; }
28: }
29: while (my $line=<FILE>) {
30: if ($line !~ /Login/) { next; }
31: my ($date,$machine)=split(':',$line,3);
32: if ($date > $start_time) {
33: push (@{$data{$date}},$user);
34: $machine{$machine}++;
35: }
36: }
37: if ($numusers%100 == 0) {
38: print "\b\b\b\b\b\b\b\b\b\b\b\b\b\bDid $user";
39: }
40: }
41:
42: sub print_data {
43: my $total_login=0;
44: my %byday;
45: print("\n");
46: foreach my $key (sort(keys(%data))) {
47: #print(scalar(localtime($key))." ".scalar(@{$data{$key}})."\n");
48: $total_login+=scalar(@{$data{$key}});
49: my $day=strftime('%F',localtime($key));
50: $byday{$day}+=scalar(@{$data{$key}});
51: while ($counts[0] && $total_login >= $counts[0]) {
52: print("The $counts[0] ($total_login) login was ".
53: join(', ',@{$data{$key}})."\n");
54: shift(@counts);
55: }
56:
57: }
58: foreach my $key (sort(keys(%byday))) {
59: print("$key -> $byday{$key}\n");
60: }
61: print("total -> $total_login\n");
62: print("\nMachine Logins\n");
63: foreach my $key (sort(keys(%machine))) {
64: print("$key \t-> $machine{$key}\n");
65: }
66: }
67:
68: $|=1;
69: sub main {
70: my $perlvar=LONCAPA::Configuration::read_conf('loncapa.conf');
71: find(
72: {
73: # preprocess => \&only_user_activitylog_files,
74: # wanted => \&print_filename,
75: # wanted => \&log_metadata,
76: wanted => \&process_activitylog_file,
77: },
78: $perlvar->{'lonUsersDir'}.'/'.$perlvar->{'lonDefDomain'});
79: &print_data();
80: }
81: &main();
82:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>