
swoop
New User
Oct 30, 2009, 9:49 AM
Post #1 of 3
(3433 views)
|
array with one element from the Telnet.pm module
|
Can't Post
|
|
I came up with a workaround to my problem with Cisco.pm. I found if I call the Telnet.pm waitfor routine I can extract the full content of the routers 'show log'. However, the array (@output) has one element which is the whole content of the 'show log'. As another workaround I put the array contents to a file, then read the file back into the script and populate another array. Then I can parse the array elements. Is there another way of doing this? I was wondering if instead of placing the array contents to a file and re-reading them back into the script if I can some how parse the array with one element (show log contents)? Below is a snippet of the code: sub scan_log { my $cmd = "show log"; my @output; my $previous = ""; my $prompt = '/.*[#>]$/i'; $session->print($cmd); @output = $session->Net::Telnet::waitfor(-match => $prompt); <<<<<<<<<<< open (OUT, "> $DIR/show_log.log"); print OUT @output; close (OUT); splice(@output,0); open (FH, "$DIR/show_log.log"); @output = <FH>; close (FH); unlink "$DIR/show_log.log"; foreach my $line (@output) { chomp($line); if ($line =~ /Trace/) { print "TRACEBACK MSG: $previous\n"; print "TRACEBACK: $line\n"; } else { $previous = $line; } } } sub node_login { my $buffer_mb = 1024 * 1024; print "Logging into node: $node ...\n"; # Login to node $session = Net::Telnet::Cisco->new(Host => $node, Timeout => $node_timeout, Prompt => $prompt); $session->send_wakeup; $session->login("$username", "$password"); $session->enable($enable_password); $session->max_buffer_length(5 * $buffer_mb); $session->cmd($zero_screen); }
|