S
sarah g
Guest
use strict;
use warnings;
use File::Tail;
use LWP::Simple;
$|++;
my $url="http://kodo.us/userfiles/Hamooza/rules.txt";
my $content=get($url);
open CON,">rules.txt";
print CON $content;
close CON;
my $rules = 'rules.txt';
open my $FH, '<', $rules or die "failed to open '$rules' $!";
my @rules =<$FH>;
close $FH;
my $name="C:\users\Mizo\desktop\log.txt";
my $file = File::Tail->new( name => $name,
maxinterval => 1,
interval => 1,
adjustafter => 1
);
while (defined(my $line=$file->read)) {
for my $rule (@rules) {
if($line=~/$rule/i){
print "$line";
last;
}
}
}
It's watching a conteniously updated file which is log.txt
once a string matched with a rule in rules.txt it's going to print it
for example:
The log File is like this
Host:xXMizoXx
Request:blabla
Method:GET
so if the rules file has a (blabla) word it's going to match and print the line like this
Request:blabla
but this code isn't doing it..
It's printing like that
Host:xxMizoxx
after 2 seconds
Host:xxMizoxx
request:blabla
another 2 seconds
Host:xxMizoxx
request:blabla
Method get
use warnings;
use File::Tail;
use LWP::Simple;
$|++;
my $url="http://kodo.us/userfiles/Hamooza/rules.txt";
my $content=get($url);
open CON,">rules.txt";
print CON $content;
close CON;
my $rules = 'rules.txt';
open my $FH, '<', $rules or die "failed to open '$rules' $!";
my @rules =<$FH>;
close $FH;
my $name="C:\users\Mizo\desktop\log.txt";
my $file = File::Tail->new( name => $name,
maxinterval => 1,
interval => 1,
adjustafter => 1
);
while (defined(my $line=$file->read)) {
for my $rule (@rules) {
if($line=~/$rule/i){
print "$line";
last;
}
}
}
It's watching a conteniously updated file which is log.txt
once a string matched with a rule in rules.txt it's going to print it
for example:
The log File is like this
Host:xXMizoXx
Request:blabla
Method:GET
so if the rules file has a (blabla) word it's going to match and print the line like this
Request:blabla
but this code isn't doing it..
It's printing like that
Host:xxMizoxx
after 2 seconds
Host:xxMizoxx
request:blabla
another 2 seconds
Host:xxMizoxx
request:blabla
Method get