Hello, I have written a library to tail the log file in a router and look for a string.

If the string is found it returns the time stamp at which the string was found.

If the string is not found it returns 0 .

the script compiles without any errors. However it returns 0 (flase) everytime even if the string is found.

It would be really helpful if someone can help me out with this. I tried various things since morning but im unable to figure it out

use strict; use warnings; sub new { my ( $this, @_ARGS ) = @_; my $class = ref($this) || $this; my $self = { _permitted => \%CLI::FIELDS, %CLI::FIELDS, @_ARGS }; bless $self, $class; # _validateFields is inherited from AKU::Object and checks to ensu +re # that what is passed as arguments to new is in the %FIELDS hash $self->_validateFields(@_ARGS); return $self->_init(); } # function to tail the logs and watch for a string. sub log_watch { my ($self, $log, $string) = @_; my $timestamp = 0; my $cmd = "type-tail $log follow"; # command to tail the file my $prompt = "::$string"; # without a terminal length of 0 some lines get split so set it ex +plicitly $self->execute( 'terminal length 0' ); # execute the command $self->execute( $cmd . $prompt ); $self->{'stdout'} = $self->get_stdout(); if ( $self->get_error() ) { # try to disconnect $self->execute("\cC"); return 0; } # try to disconnect $self->execute("\cC"); foreach my $line ( @{ $self->{'stdout'} } ) { if ( $line =~ m/^(\d+\/\d+\/\d+\s\d+\:\d+\:\d+\.\d+)/msx ) { $timestamp = $1; } DEBUG("Line: $line"); } return $timestamp; }

Im using the above lib in a sample script as below

Function call :
sub testMain { my $log_obj = LogUtils->new( ip => 'ip addr ' ); my $retrieval_time = $log_obj->log_watch( 'logfile.txt', # file name 'm-ns - - 200 GET http://www.google.com' # string to be searched ); INFO("Found retrieval of the specified string at $retrieval_time");

below is the output

output : 20140806T003044 INFO Found retrieval of the specified string at 0

In reply to tailing the file and look for string by user786

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.