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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.