perl_zen_noob has asked for the wisdom of the Perl Monks concerning the following question:
I'm pretty new to perl. I'm trying to tail a log file (in any way) and match the output with a string to determine the next course of action. I've tried tailing a few ways, but I can't seem to get the tail to match the string that I'm searching for.
Here are the last few lines of the log that I'm tailing (/var/log/ping_10.10.0.100):
02-23-2010 11:20:01 10.10.0.100 is alive! 02-23-2010 11:30:01 10.10.0.100 is alive! 02-23-2010 11:40:01 10.10.0.100 is alive! 02-23-2010 11:50:01 10.10.0.100 is alive!
Here's my closest script:
#!/usr/bin/perl use strict; use warnings; my $tail = system("tail -1 /var/log/ping_10.10.0.100.sj"); #print "$tail\n"; if ($tail =~ m/alive/) { print "match\n"; } else { print "no match\n"; }
Sadly, it only returns a match if I try to match "0". Of course, I'm trying to match the word "alive". What am I doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tail a log, then match its string
by toolic (Bishop) on Feb 24, 2010 at 03:14 UTC | |
by perl_zen_noob (Initiate) on Feb 24, 2010 at 03:38 UTC | |
|
Re: Tail a log, then match its string
by Anonymous Monk on Feb 24, 2010 at 05:53 UTC | |
|
Re: Tail a log, then match its string
by Anonymous Monk on Feb 24, 2010 at 03:07 UTC |