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: Perl Programming Help: Regular Expressions: Re: [namishtiwari] perl script help: Edit Log



1arryb
User

Jun 10, 2009, 7:35 AM


Views: 16340
Re: [namishtiwari] perl script help

Hi namishitwari,

Easy-peasey. The perl glob() command is what you're looking for. You'll need to pass the log directory and log prefix to your script instead of a file name and add an outer loop to handle the multiple files. Perhaps something like:

Code
... 
my $logDir = $ARGV[0];
my $logPrefix = $ARGV[1]
die "usage: $0 <logDir> <logPrefix>" unless $logDir and $logPrefix;
die "Log dir $logDir doesn't exist" unless -d "$logDir";
for my $logFile ( glob("$logDir/${logPrefix}*") ) {
# Process $logFile as before.
...
}


Depending on whether you want per-file or summary statistics, you can keep the output code where it is or move it outside of the loop on $logFile.

UPDATE:

I didn't see the bit about timestamps. Getting the timestamp is easy.

Code
... 
# Note: The '(?:...)' regex means "group these regular expressions but don't remember the match".
if ( $line =~ /^(.*) INFO:.*(?:userName [:]|UPAuth SUCCESS for user|OTP SUCCESS for user)(?:\(|\[)(\S*)(?:\)|\])/ ) {
my $timestamp = $1;
my $userName = $2 ? $2 : "NULL";
...


The trick will be if you need to convert the timestamp to some other format. That can be a chore.

UPDATE2:

I'm also not sure what you intend to do with the timestamps. You'll have to change your output to report each session, instead of summarizing sessions per authMethod.

Cheers,

Larry


(This post was edited by 1arryb on Jun 10, 2009, 8:28 AM)


Edit Log:
Post edited by 1arryb (User) on Jun 10, 2009, 8:02 AM
Post edited by 1arryb (User) on Jun 10, 2009, 8:28 AM


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

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