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 ensure # 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 explicitly $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; } #### 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");