xnd has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use Env; $LOGDIR="/hlds/cstrike/logs"; $USERS="/hlds/cstrike/addons/adminmod/config/users.ini"; $search='\bconnected, address\b' ; open USERS, "<$USERS" or die "cannot open $USERS:$!"; while (<USERS>) { chomp; push @users, ((split /:/)[0]); } print "search:@users\n"; @ARGV = <$LOGDIR/*.log> ; while (<ARGV>) { next unless /$search/o; s/L//; s/<.*>//; s/$search//o; s/ /:/; s/ - /-/; #print; my $nm = name_match( (split)[1]); next unless $nm; # print "$nm=>$_" if $nm; my ($time, $name, $addy) = split; my $stamp = fix_time ($time); #print "[$stamp]\n"; my $rec = "$stamp $time $name"; if (exists $R{$nm}) { my $t = (split " ", $R{$nm})[0]; # print "if ( $stamp < $t ) \n"; if ( $stamp < $t ) { $R{$nm} = $rec; } } else { $R{$nm} = $rec; } } print "--------------------------\n"; @values = sort values %R; foreach $v (@values) { print STDOUT (split /:/, $v, 2)[1]; print "\n"; } # compare names, log names may have attributes; like sub name_match { my $nm = shift; $nm =~ tr/"//d; foreach $user (@users) { return $user if $nm =~ /$user/; } return ""; } # convert time from 'L: MM/DD/YYYY - hh:mm:ss' to YYYYMMDDhhmmss # which makes time comparison a doddle sub fix_time { local $_ = shift; s/.//; tr/://d; my($date, $time) = split /-/; my ($m, $d, $y) = split "/", $date; return "$y$m$d$time"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A pretty simple perl script..
by GrandFather (Saint) on Mar 30, 2006 at 21:46 UTC | |
by xnd (Initiate) on Mar 30, 2006 at 22:51 UTC | |
by GrandFather (Saint) on Apr 01, 2006 at 01:00 UTC | |
|
Re: A pretty simple perl script..
by wedgef5 (Scribe) on Mar 30, 2006 at 21:40 UTC | |
by GrandFather (Saint) on Mar 30, 2006 at 21:48 UTC | |
|
Re: A pretty simple perl script..
by zshzn (Hermit) on Mar 30, 2006 at 21:37 UTC | |
|
Re: A pretty simple perl script..
by Anonymous Monk on Mar 31, 2006 at 00:28 UTC | |
by xnd (Initiate) on Mar 31, 2006 at 09:00 UTC | |
by jwkrahn (Abbot) on Mar 31, 2006 at 13:53 UTC | |
|
Re: A pretty simple perl script..
by xnd (Initiate) on Mar 30, 2006 at 23:33 UTC | |
by eric256 (Parson) on Mar 31, 2006 at 15:02 UTC |