sout11 has asked for the wisdom of the Perl Monks concerning the following question:
Hello there. I have been trying to logon to switches using an array to collect switch IPs and then log onto the switches. I got 2 different ways that I have to use to log on to the switches depending on the configuration of the switches. Some of the switches require a username and password and some only require a password, here is my code for both ways:
#login 1 foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new( +HOST => $host); # connect to the host $conn->login( Name => $username, Password => $password); $conn->close; }; #Login 2 foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new( +HOST => $host); # connect to the host $conn->login( Passcode => $passw); $conn->close; };
Both these login ways is tested and works on switches with the different configs. What I want to do is to have both of these in one script so that I can run through the whole range of switches. I was thinking of using an IF statement, but being a noob I dont really know where to start. This is what I was thinking about doing:
foreach $host ( @hosts ) { my $conn = Net::Telnet::Cisco::IOS->new +(HOST => $host); # connect to the host if ( $conn->login( Name => $username, Password => $password)); else( $conn->login( Passcode => $passw));
I know my coding layout is wrong and I am not looking to be spoon fead, but would like someone to point me in the right direction. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net telnet Cisco Login
by moritz (Cardinal) on Aug 25, 2009 at 12:29 UTC | |
by sout11 (Initiate) on Aug 25, 2009 at 13:52 UTC | |
|
Re: Net telnet Cisco Login
by ssandv (Hermit) on Aug 25, 2009 at 15:44 UTC | |
by sout11 (Initiate) on Aug 26, 2009 at 07:44 UTC | |
by ssandv (Hermit) on Aug 26, 2009 at 14:48 UTC |