in reply to Re^3: Undefined Error
in thread Undefined Error

Thank You, both works ( /b and /s). One last query related to this post, I would like to add time search, where the time has following format :

[04/Jun/2013:15:06:13

I would like to scan the log for last one hour only whenever I run the script. Thanks for all your effort.

Replies are listed 'Best First'.
Re^5: Undefined Error
by poj (Abbot) on Jun 15, 2013 at 17:13 UTC
    Remove the extra print statements if you are happy it works as expected.
    use strict; use warnings; ## add this use DateTime::Format::Strptime qw(strptime); my $NOW = DateTime->now(); my $MAX_AGE = 60; print "Time now is $NOW\n"; ## my %users; my %conn; while (<DATA>) { # I use DATA handle instead of $fh for convenience if( /\bBIND\b/ ) { my( $conn, $uid ) = /conn=(\d+).*uid=(.*?),/; $conn{$conn} = $uid; } if( /SRCH=Q/ ) { my ($timestamp, $conn) = /\[(.*?)\] conn=(\d+)/; ## add this my $dt = strptime('%d/%B/%Y:%T',substr($timestamp,0,20)); my $age = $dt->delta_ms( $NOW )->in_units('minutes'); print $timestamp." = " .$dt->datetime." ; $age mins\n"; ## ## add condition if ($age >= $MAX_AGE){ my $uid = $conn{$conn}; ++$users{$uid}; } } } for my $uid (keys %users) { my $count = $users{$uid}; print "\t=> Bad user $uid ! count = $count\n" if $count > 3; }
    poj