Hi All I am still trying to create a script to tail a log file and report on an instant or exception when a message is not recieved. This means I will be searching for a string in a log file which is constant meaning what ever is writing to the log file does this all the time. Now if I don't recieve a message from whatever is writing to the log within 60 seconds I would like to create a exception error e.g ( print STDERR "Have not recieved a message in the last 60 seconds"; ) I am finding creating this exception timer part the difficult bit. I have attached my code below and would like some advice on if I am on the right track. Any assistance would be much appreciated. Kind Regards James
use IO::Select; $select = IO::Select->new(); # repeat next two lines for all filehandles to poll open(LOGFILE, "< james.log") || die; seek(LOGFILE, 0, 2); $select->add(*LOGFILE); for (;;) { if (@ready = $select->can_read) { # input waiting on the filehandles in @ready foreach $filehandle (@ready) { while (<$filehandle>) { chomp(); if (m/^Hello/) { print STDERR "This is a hello msg"; $starttime = time; } } } sleep 2; $endtime = time; print STDERR "$starttime\n"; print STDERR "$endtime\n"; } } $timediff = $endtime - $starttime; if ( $timediff = "60" ) { print STDERR "Have not recieved a message in the last + $timediff seconds"; }

In reply to Log file tailing by wellsja

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.