#!/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 () { chomp; push @users, ((split /:/)[0]); } print "search:@users\n"; @ARGV = <$LOGDIR/*.log> ; while () { 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"; }