I have written a couple of functions for tailing the logs and grep for a string.
I grep for the string 100.81.2.59:4500', 'dst:172.25.150.190:4500'.
When the function is called the logs are tailed as expected,The above mentioned strings are also present in the logs but the function always returns false.
WARN Not found "string" n ipsecd.log
Function:
sub tail_logs{ my ($self) = @_; my $cmd = 'tail -n 500 /a/logs/ipsecd.log | grep NAT'; $self->execute('$cmd'); if ($self->execute($cmd)) { return $self->get_stdout(); } else { die " Failed to execute $cmd"; } }
sub grep { my ($self,$logLines, @strings) = @_; for my $string (@strings) { if ( $logLines =~ /$string/ ) { INFO("Found $string in ipsecd.log"); } else { #return false, we cound find $string WARN("Not Found $string in ipsecd.log"); return 0; } } # found all strings in the $loglines, return true. return 1; }
Function call : ,
my @checkStrings = ('100.81.2.59:4500', 'dst:172.25.150.190:4500'); $self->{'log'} = $self->{'log_obj'}->tail_logs(); $self->{'log_verify'}= $self->{'log_obj'}->grep($self->{'log'}, @ch +eckStrings); if ( $self->{'log_verify'} ) { $self->assert( $self->{'log_verify'}, 'Found info in ipsecd.logs' );
Loglines
[04-15 21:17:04.614251 (05026) D ipsec_processor.: 496] processOutbou +nd: IPsec EDP-UDP (NAT-T) packet to destination - src addr:100.81.2.5 +9:4500 dst:172.25.150.190:4500 [04-15 21:17:04.821548 (05026) D ipsec_processor.: 496] processOutbou +nd: IPsec EDP-UDP (NAT-T) packet to destination - src addr:100.81.2.5 +9:4500 dst:172.25.150.190:4500 [04-15 21:17:05.029262 (05026) D ipsec_processor.: 496] processOutbou +nd: IPsec EDP-UDP (NAT-T) packet to destination - src addr:100.81.2.5 +9:4500 dst:172.25.150.190:4500 [04-15 21:17:05.237628 (05026) D ipsec_processor.: 496] processOutbou +nd: IPsec EDP-UDP (NAT-T) packet to destination - src addr:100.81.2.5 +9:4500 dst:172.25.150.190:4500 [04-15 21:17:05.444636 (05026) D ipsec_processor.: 496] processOutbou +nd: IPsec EDP-UDP (NAT-T) packet to destination - src addr:100.81.2.5 +9:4500 dst:172.25.150.190:4500
In reply to Perl: Function to search for a string by user786
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |