ericj has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: Net::Telnet::Cisco, a question
by fokat (Deacon) on Dec 17, 2001 at 22:34 UTC
    I believe Net::Telnet::Cisco is not "warnings" safe. Replace the -w switch in the #! line with an use warnings, which does not leak into the Net::Telnet::Cisco code. You shouldn't have to issue the enable commands in the way you're doing it. You should call the ->enable($password) method as per the Net::Telnet::Cisco docs.
Re: Net::Telnet::Cisco, a question (ditch the arugment 'login')
by ybiC (Prior) on Dec 18, 2001 at 08:37 UTC
    Even though perldoc Net::Telnet::Cisco has an example using this syntax, I believe the problem is in this line:
    my $ok = $cs->login('login', $switchPassword) or die "Error logging in: @{[ $cs->errmsg+() ]}\n";

    You probably shouldn't have the word login as the first argument.   Try empty single quotes instead, like so:
    $ok = $cs->login('', $switchPassword) or die "Error logging in: @{ $cs->errmsg+() }\n";
    since the first agument is userID.

    Additional info can be found at perldoc Net::Telnet.   I don't have access to chassis Catalysts for the time being, otherwise I'd take your code out for a spin.   So please feel free to /msg me or post a reply to this node if any other questions.
        hope this helps,
        Don
        striving toward Perl Adept
        (it's pronounced "why-bick")

    p.s. I could be wrong, but AFAIK, the only difference between 'use warnings' and '-w' is what versions of the Perl interpreter support them - the former only on 5.6 or greater, the latter useable from waaay back to 4.something props to tye for the ancient history {grin}.

    p.p.s. Welcome to the Monastery, ericj!

      Thanks for the welcome and the advice. As far as I can tell, Net::Telnet::Cisco works on anything running IOS. I have not been able to get this to work on any Cisco devices running the Catalyst OS. I think I may have to change the perl mod to work on these.