
xnd
New User
Mar 31, 2006, 12:41 AM
Post #3 of 4
(1313 views)
|
|
Re: [KevinR] I need a simple script..
[In reply to]
|
Can't Post
|
|
yes, but it's not working properly.. it shows that some names have last connected a long time ago (two, three weeks ago) but i know for sure that those names have connected today or yesterday :|
#!/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"; }
|