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

In reply to Net::Telnet::Cisco Using a Global Session by spickles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.