I have been using Net::Telnet::Cisco to get information out of cisco routers.(6000 Chasssis running Hybrid.) I use the information to populate a database and keep track of different things on the network. I would like to add information from the layer 3 switch also.(port information for the layer 3 vlans.) The problem is that I can't login to the switch. If I use the wrong password it tells me that the password is wrong, but when I use the correct password I get,
"Use of uninitialized value in pattern match (m//)at /usr/local/lib/perl5/site_perl/5.6.1/Net/Telnet/Cisco.pm line 410, <STDIN> line 2." Here is a sample of the code I am using to test getting into the switch.
#!/usr/local/bin/perl -w use Net::Telnet::Cisco; use strict; my $debug = 1; my $IP_Addr = ""; my $switchPassword = ""; my $routerPassword = ""; my $routerEnPassword = ""; my $switchEnPassword = ""; ## Get the IP Address if ($IP_Addr eq "") { print "Enter the IP Address: "; chop($IP_Addr = <STDIN>); system("stty echo"); print "\n"; } ## Get the switchPassword (make it invisible when entering) if ($switchPassword eq "") { print "Enter the switch password: "; system("stty -echo"); chop($switchPassword = <STDIN>); system("stty echo"); print "\n"; } print "\tConnecting to $IP_Addr\n" if ($debug); my $cs = Net::Telnet::Cisco->new(Host => $IP_Addr); my $ok = $cs->login('login', $switchPassword) or die "Error lo +gging in: @{[ $cs->errmsg() ]}\n"; print "Logged into Switch\n" if ($debug); #Turn off paging my @cmd_output = $cs->cmd( 'terminal length 0' ); #Enter enable mode if ($switchEnPassword eq "") { print "Enter the enable password for the switch: "; system("stty -echo"); chop($switchEnPassword = <STDIN>); system("stty echo"); print "\n"; } $ok = $cs->cmd("enable\n$switchEnPassword"); print "entered enable mode\n"; my @portInfo = $cs->cmd("sho port status "); print "Here"; my $arrayElement; foreach $arrayElement (@portInfo) { print "$arrayElement\n"; } ## end foreach() $ok = $cs->disable; $ok = $cs->cmd("session 15\n$routerPassword"); $ok = $cs->cmd("enable\n$routerEnPassword"); my @intStuff = $cs->cmd("dir"); foreach $arrayElement (@portInfo) { print "$arrayElement\n"; } ## end foreach() exit;
I believe the problem is with my prompt. The only difference I see between the prompts of the router, and the prompts of the switch is that with the router prompts "Password:" and the switch prompts "Enter password:". If anyone knows what I can do to fix this problem I would be very grateful.

In reply to Net::Telnet::Cisco, a question by ericj

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.