#! perl -slw use strict; use constant LOGFILENAME => 'your logfile name goes here'; use constant CHUNKSIZE => 100; # Vary this to suit your application. open my $log, '<', LOGFILENAME or die $!; # Should use the constants here, but its easier to remember the numbers than # remember the names of the constants and which module to pull to import them. seek $log, 0, 2; my($lastsize, %events) = (-s LOGFILENAME); while(1) { my $size = -s LOGFILENAME; if ($size > $lastsize + CHUNKSIZE) { # Has the file grown (enough)? my $line = <$log>; #Read the next available line my $now = time; # Record the time print $now, ' : ', $line; # Just for testing $lastsize += length $line; # remember the new position. if ($line =~ m[ICMP]) { # Check for condition # Schedule an event of met. push @{ $events{$now + 20} }, ['This condition occured 20 seconds ago', $line]; } elsif ($line =~ m[:137]) { push @{ $events{$now + 10} }, ['This condition occured 10 seconds ago', $line]; } } # Should give accuracy to within 1 sec by your systems clock. select undef, undef, undef,0.5; my $now=time; if (exists $events{$now}) { # Check for iminant events for my $event (@{ $events{$now} }) { # Process them all print $event->[0], $/, $event->[1]; } delete $events{$now}; # Remove them when done } }