I have a script that is broken up into various subroutines. One version is very slow and stable in which I open and close the telnet session in each sub when I need to. I am now trying to avoid that and speed things up by declaring the session early on (before subs) so as to be global. I currently have a global connection to my MySQL database and I can use it inside and outside subs with no problem. When I run my script using the global telnet session, however, it crashes on the first sub that uses the session. I have tried passing the session into the sub and returning it back out as well with no success. Can anyone think of a reason as to why the global db connection is working fine but not a global telnet session?
<snip>
my $host = "172.16.0.2";
my $session = Net::Telnet::Cisco->new(
Host => $host,
Prompt => '/\(Cisco Controller\)/',
Errmode => 'return',
Timeout => 5);
$session->open($host);
# Wait for the username prompt and enter username
$session->waitfor('/^User:.*$/');
$session->print($username);
# Wait for the password prompt and enter password
$session->waitfor('/^Password:.*$/');
$session->print($password);
$session->cmd("config paging disable");
<snip>
#Inside subroutine
my @output;
my $input_log = $directory . "/" . $host . "_get_ap_summary_in.log";
my $output_log = $directory . "/" . $host . "_get_ap_summary_out.log";
$session->input_log($output_log);
$session->output_log($input_log);
@output = $session->cmd("show ap summary");
Regards,
Scott