Hello expert,
I'm facing with a strange behaviour from Net::Telnet trying to get the command output from a Cisco device.
The result from "show run" command is placed into a scalar but printing the contents I get a number.
The dump log contests the right output.
Below the simple code that I'm using.
#/opt/ActivePerl-5.18/bin/perl
use Net::Telnet;
eval {
$t = new Net::Telnet ( Timeout=>10, Errmode=> 'die', Prompt=> '/[#
+>] $/' );
$t->open("x.x.x.x");
};
if($@) {
print "error: " . $@ . "\n";
} else {
print "success: " . $@ . "\n";
}
$t->dump_log("file_dump");
$t->output_log("file_out");
#$t->max_buffer_length(50*1024*1024);
$t->waitfor('/Username: ?$/i');
$t->print("*****");
$t->waitfor('/Password: ?$/i');
$t->print("*****");
$t->waitfor(-match=> '/> ?$/', -errmode=> "return") or die "login fail
+ed: ", $t->lastline;
$t->print("en");
$t->waitfor('/Password: ?$/i');
$t->print("*****");
$t->waitfor(-match=> '/# ?$/', -errmode=> "return") or die "login enab
+le failed: ", $t->lastline;
#$t->cmd(-string=> 'terminal pager 0', -timeout=> 30, -prompt=> '/# $/
+');
#$t->waitfor(-match=> '/# $/', -errmode=> "return") or die "prompt not
+ returned: ", $t->lastline;
#@lines=$t->cmd(-string=> 'show run', -timeout=> 30, -prompt=> '/# $/'
+);
$t->print('terminal pager 0');
$t->waitfor('/# $/');
@showrun=$t->cmd('show run');
print @showrun . "\n";
print "moving to next statement\n";
running the script I get:
success:
2280
moving to next statement
Anyone can help me ?
Thanks
**************************************************************
I resolved, don't understand why but the command
print @showrun . "\n";
prints the numbers of element into the array.
The following code show the array contents:
print("@showrun\n");