I have a program that basically opens and reads the syslog in ubuntu and use a keyword text file to search for specific words in the syslog and have that to be outputted into an output text file. Problem is, it was all going well until I can't seem to get any errors anymore which doesn't really help me as there is a mistake somewhere which makes me not see any output at all. I ran my regex using a perl online testing tool and it works but doesnt seem so when I try to run it on the terminal. I would be glad if someone could help me with this.
Here is my code:
#!usr/bin/perl
use strict;
use warnings;
my $syslogFile = 'syslog';
open (my $syslogInfo, '<', $syslogFile) or die "Could not open $syslogFile";
my $keywordFile = 'keyword';
open (my $keywordInfo, '<', $keywordFile) or die "Could not open $keywordFile";
while (my $line = <$syslogInfo>)
{
if($line =~ m/[a-zA-Z]\s(\d{1-31})\s(\d{1-24}):(\d{1-59}):(\d{1-59})\s[a-zA-Z]\s($keywordInfo).\ni/)
{
open(outputFile, ">>output");
flock(outputFile, 2);
print outputFile "$line\n";
}
}
Edit: Here is a sample of what is in the syslog
Dec 29 22:02:28 osboxes NetworkManager[686]: plen 24 (255.255.255.0)