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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions: Re: [namishtiwari] perl script help: Edit Log


Jun 10, 2009, 7:35 AM

Views: 40301
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:

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.


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

# 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.


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.



(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