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?
In reply to Tail a log, then match its string by perl_zen_noob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |