#!/usr/bin/perl -w
use strict;
use warnings;
use File::Tail;
use Parse::Syslog;
my $log = File::Tail->new("/var/log/syslog");
my $parser = Parse::Syslog->new($log);
while(my $sl = $parser->next) {
print qq[
program $sl->{program}
with pid $sl->{pid}
on host $sl->{host}
said $sl->{text}
at $sl->{timestamp}
];
}
| We're not surrounded, we're in a target-rich environment! |
|---|
| [reply] [d/l] |
Interesting. The code above does not seem to work so far. The Tail part does not seem to notice when the log file changes. I'll continue to investigate. One thing about this method that troubles me is that this involves keeping another process running full time. If the log was piped from syslog to the script instead I'd only need to ensure that syslog was running.
This leads to my next question. How can data be passed from STDIN to Parse::Syslog?
#!/usr/bin/perl
use strict;
use warnings;
use Parse::Syslog;
my ($parser, $sl);
while (<>){
$parser = Parse::Syslog->new($_);
while($sl = $parser->next) {
print "here\n";
print qq[
program $sl->{program}
with pid $sl->{pid}
on host $sl->{host}
said $sl->{text}
at $sl->{timestamp}
];
}
}
This code returns an error " No such file or directory at ./logfilter.pl line 10".
| [reply] [d/l] |
| [reply] |