CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
I need a simple script..

 



xnd
New User

Mar 30, 2006, 1:10 PM

Post #1 of 4 (1713 views)
I need a simple script.. Can't Post

Hello all!

I have a file named "users.ini" wich contains lines like this:


Code
name1:password:accesslevel 
name2:password:accesslevel

etc

and a directory with logs like this: L0328000.log, L0328001.log, L0328002.log etc.

So what i need is a perl script that takes name1 from users.ini, searches it in all the logs and then prints the last time that name connected. Then takes name2, does the same thing and so on. And then, sorts the lines by date and writes them in a html or txt file.. doesn't really matter.

Oh, and the logs contain lines like this:
L 03/30/2006 - 11:59:17: "name1<62><STEAM_ID_LAN><>" connected, address "192.168.1.1:27005"

In the end i need it to print something like this:

Name: Last connected:
name1 01 03 2006
name2 02 03 2006

Your help will be very much apreciated! Thank you!


KevinR
Veteran


Mar 30, 2006, 6:46 PM

Post #2 of 4 (1707 views)
Re: [xnd] I need a simple script.. [In reply to] Can't Post

have you tried writing any code yourself?
-------------------------------------------------


xnd
New User

Mar 31, 2006, 12:41 AM

Post #3 of 4 (1706 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 :|


Code
#!/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";
}



KevinR
Veteran


Mar 31, 2006, 1:50 AM

Post #4 of 4 (1703 views)
Re: [xnd] I need a simple script.. [In reply to] Can't Post

make sure this line is doing what you want:

if ( $stamp < $t ) {

print $stamp and $t so you can see what is getting compared
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives