Here is some example code. Unless you have a Cisco controller, you can't actually run this and get meaningful output. The script completes, but the output to the various logs is all wrong. I think I need to find a way to wait for the prompt again so that it slows things down. I think the script is happening too quickly, the log inputs/outputs are getting created before the first subroutine has ended and the output for sub get_ap_summary shows up in the output log for show_inventory. The prompt is '(Cisco Controller) >', and I thought I set that in the properties of the session object, but perhaps the regex doesn't match? I thought if I changed the prompt in the session object that it would always wait (IOW, I thought the default setting is 'always wait for prompt').

#!c:/perl/bin/perl use strict; use warnings; use Net::Telnet::Cisco; use DBI; use DBD::mysql; use Env; use File::Path; use File::Basename; use IO::Handle; use Config::IniFiles; use Term::ReadKey; ###################################################################### +################################## # Global Variables ################################################### +################################## ###################################################################### +################################## my $username = "admin"; my $password = "admin"; my $host = "172.16.0.2"; my @output; my $input_log; my $output_log; my $directory = "c:/perl/bin/test/"; #Check for the presence of the log file directory. If not there, crea +te it eval { mkpath($directory); if ($@) { print "Couldn't create path: $@"; } else { mkpath($directory); } }; ###################################################################### +################################## # Global Variables ################################################### +################################## ###################################################################### +################################## ###################################################################### +################################## # Controller Connection ############################################## +################################## ###################################################################### +################################## system "cls"; print "Connecting to controller ...\n"; 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"); ###################################################################### +################################## # Controller Connection ############################################## +################################## ###################################################################### +################################## get_ap_summary(); show_run(); show_inventory(); cleanup(); exit(); ###################################################################### +################################## # Subroutines ######################################################## +################################## ###################################################################### +################################## sub get_ap_summary { print "\nGetting AP Summary ...\n"; #my @output; $input_log = $directory . $host . "_get_ap_summary_in.log"; $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"); return; } sub show_run { print "\nGetting Running Config ...\n"; #my @output; $input_log = $directory . $host . "_get_run_config_in.log"; $output_log = $directory . $host . "_get_run_config_out.log"; $session->input_log($output_log); $session->output_log($input_log); @output = $session->cmd("show run-config"); return; } sub show_inventory { print "\nGetting inventory ...\n"; #my @output; $input_log = $directory . $host . "_get_inventory_in.log"; $output_log = $directory . $host . "_get_inventory_out.log"; $session->input_log($output_log); $session->output_log($input_log); @output = $session->cmd("show inventory"); return; } sub cleanup { print "\nClosing telnet connection ...\n"; $session->cmd("config paging enable"); $session->close; print "FINISHED\n"; } ###################################################################### +################################## # Subroutines ######################################################## +################################## ###################################################################### +##################################

In reply to Re^2: Net::Telnet::Cisco Using a Global Session by spickles
in thread 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.