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

Hi everyone,

I am currently trying to pull the running config from various Cisco devices. I decided I would start with the basics and pull from one device to start with and then alter the script. My issue is that I can't even get that right!

When running the below script it is constantly asking for the password. If I manually provide the same password (when prompted) that is referenced in the script I can see on the switch that it logs in successfully, however the script keeps on prompting for it.

use strict; use warnings; use Net::Appliance::Session; my $ios_device_ip = '10.10.1.1'; my $ios_username = 'redacted'; my $ios_password = 'redacted'; my $running_config_file = "$ENV{HOME}/running_config.txt"; my $session_obj = Net::Appliance::Session->new( host => $ios_device_ip, personality => 'ios', transport => 'SSH', ); # try to login to the ios device, ignoring host check $session_obj->connect( Name => $ios_username, Password => $ios_password, SHKC => 0 ); # get our running config my @running_config = $session_obj->cmd('show running'); # chop out the extra info top and bottom of the config @running_config = @running_config[ 2 .. (@running_config -1)]; open(FH, "> $running_config_file") or die("Cannot open config file : $!"); print FH @running_config; close FH; # close down our session $session_obj->close;

The password does have special characters in it. I have tried using the " quotes round the password but hasn't made any difference.

Could anyone advise on what I should be looking at?

Replies are listed 'Best First'.
Re: Issue with Net::Appliance::Session
by roboticus (Chancellor) on Jun 09, 2015 at 11:23 UTC

    ThePerlNoob:

    I'd suggest temporarily changing the password to one having no special characters to test it. That will show you whether the content of the password has something to do with it (in which case you need to figure out how to escape the special characters) or if there's a logic error in the code. (I don't use the module, so I wouldn't notice anything not painfully obvious.)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thank you for the reply.

      I was not able to remove the complexity at the time due to the kit being in production however I have built another device up to test with. That is now running a simple password and it still doesn't work. It's like the password isn't being sent. I will keep looking.

        ThePerlNoob:

        Ok, if you've eliminated the password, I'd try turning on the logging for the session, and turn up the detail to see if there are any clues in that. I'm guessing that there may be a problem establishing an SSH connection. Another option would be to try a telnet connection to see if there's a difference.

        You may also want to show some of the output of the program, and add some traces to your code so you can tell which lines are having the problem. (Since you don't specify, I expect it's the connect call.)

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.