http://www.perlmonks.org?node_id=983207


in reply to Re: Perl Script to enable Cisco
in thread Perl Script to enable Cisco

Thanks for the clarification with /n What I mean by enable command is this... On a Cisco there is a whole subset of commands you can run from privileged mode. To do that you type the command "enable" and then are prompted for a password. Im just not sure how I go about scripting that out.

I tried like this, but it didnt work

###run commands### $ssh->cmd("enable theEnablePassword");
Tried like this too
$ssh->cmd("enable"); $ssh->cmd("theEnablePassword");
Not sure if I explained that right.

Replies are listed 'Best First'.
Re^3: Perl Script to enable Cisco
by dasgar (Priest) on Jul 23, 2012 at 18:13 UTC

    Since it sounds like you'll need to your script to interactively respond to the remote device, I think that you need to use something like Expect.

    I personally have never used expect, so I can't offer up more details on how to use expect. Based on my limited knowledge of expect, I believe that it can be used to issue a command, what for a specific response, and then issue another command based on the response received.

      Ok I'll give it a try, Im pretty stumped right now.

      There is actually a module out there that does what I am trying to do called Net::Telnet::Cisco

      It supports an enable feature specific for Cisco $session->enable("enable_password")

      This would do the trick but the problem is our Ciscos are running SSH not Telnet so I am using Net::SSH::Perl which does not have the same enable option as N::T::C

      Is anyone aware of a way I could modify the NTC module to use SSH instead of telent?

Re^3: Perl Script to enable Cisco
by aitap (Curate) on Jul 23, 2012 at 17:33 UTC
    What do these commands return? I mean, what if you try to say $ssh->cmd("enable theEnablePassword");?
    Sorry if my advice was wrong.
      Heres the outout I get when I run the script, I tried adding the say but it produced the same results.

      Layer-2 Switch Line has invalid autocommand "show running-config"

      In order for me to execute the show run config I need to get the box into enabled mode. I copied the sequences below from the CLI of me running the commands manually. Hopefully it will help illustrate what I am trying to do.

      Switch-01>enable <--- Log on to box and type enable

      Password: <---prompts for password

      Switch-01#sho run <--- drops into privilege mode where I can run the show run command

      Building configuration...

      also I was able to get rid of the newline character by adding

      chomp ($filename);

        Please, use our HTML-like markup on your posts, especially <code>...</code> tag. Note that you can edit your messages anytime.
        Sorry if my advice was wrong.