Reply

Help with scripting to HP Procurve

Techie
Posts: 7
18289     0

When I try to run a simple script to change passwords on a 2524, I keep getting the below running instead of my script. Is there a way to make this stop? Thanks

 

Password:

 

sw-dr1-taperoom# enable

sw-dr1-taperoom# conf t

sw-dr1-taperoom(config)# console local-terminal none

sw-dr1-taperoom(config)# end

sw-dr1-taperoom# terminal length 1000

 

sw-dr1-taperoom# terminal width 1920

 

sw-dr1-taperoom# no page

sw-dr1-taperoom#

*** Job Completed Successfully ***

Re: Help with scripting to HP Procurve

Superuser
Posts: 115
18289     0

Can you post the script and remove the new password?

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Help with scripting to HP Procurve

Techie
Posts: 7
18289     0

Thank you. It does match the scropt block fine and connects to the switch just fine according the session logs. its more than likely something I am doing and I am fairly new to this. Thanks again

 

 

# BEGIN-SCRIPT-BLOCK

#
## 
#
# Script-Filter:
# $Vendor eq "HP" and
# $type eq "Switch" and
# $sysDescr not like /IOS/ and
# $sysLocation not like /DMZ/ and
# $sysLocation not like /chq/
#
#
#
#
#
##----------------------------------------------------------------------
## Script-Variables are defined to allow the user to provide input
## to the script. In this example, the user will be prompted to
## enter a username and password prior to script execution. The
## username is defined as type "word", which means any string
## without whitespace can be entered. The password is defined as
## type "password", which means any string can be entered, however
## only stars will be displayed.
##
## These fields define the GUI prompts to be displayed to the user when the script is executed.
##----------------------------------------------------------------------
# Script-Variables:
#
#
# $new_op_pass password "New operator read password"
# $new_mgr_pass password "New manager enable password"
#
#
# END-SCRIPT-BLOCK
##




from infoblox_netmri.easy import NetMRIEasy

defaults = {
"api_url": api_url,
"http_username": http_username,
"http_password": http_password,
"job_id": job_id,
"device_id": device_id,
"batch_id": batch_id
}



with NetMRIEasy(**defaults) as easy:


easy.send_command("conf t\n");
easy.send_command("password all\n");
easy.send_command("new_op_pass\n");
easy.send_command("new_op_pass\n");
easy.send_command("new_mgr_pass\n");
easy.send_command("new_mgr_pass\n");
easy.send_command("exit\n");
easy.send_command("exit\n");
easy.send_command("y\n");

Re: Help with scripting to HP Pro-curve

Techie
Posts: 7
18289     0

Thank you. It does match the scropt block fine and connects to the switch just fine according the session logs. its more than likely something I am doing and I am fairly new to this. Thanks again

 

 

# BEGIN-SCRIPT-BLOCK

#
## 
#
# Script-Filter:
# $Vendor eq "HP" and
# $type eq "Switch" and
# $sysDescr not like /IOS/ and
# $sysLocation not like /DMZ/ and
# $sysLocation not like /chq/
#
#
#
#
#
##----------------------------------------------------------------------
## Script-Variables are defined to allow the user to provide input
## to the script. In this example, the user will be prompted to
## enter a username and password prior to script execution. The
## username is defined as type "word", which means any string
## without whitespace can be entered. The password is defined as
## type "password", which means any string can be entered, however
## only stars will be displayed.
##
## These fields define the GUI prompts to be displayed to the user when the script is executed.
##----------------------------------------------------------------------
# Script-Variables:
#
#
# $new_op_pass password "New operator read password"
# $new_mgr_pass password "New manager enable password"
#
#
# END-SCRIPT-BLOCK
##




from infoblox_netmri.easy import NetMRIEasy

defaults = {
"api_url": api_url,
"http_username": http_username,
"http_password": http_password,
"job_id": job_id,
"device_id": device_id,
"batch_id": batch_id
}



with NetMRIEasy(**defaults) as easy:


easy.send_command("conf t\n");
easy.send_command("password all\n");
easy.send_command("new_op_pass\n");
easy.send_command("new_op_pass\n");
easy.send_command("new_mgr_pass\n");
easy.send_command("new_mgr_pass\n");
easy.send_command("exit\n");
easy.send_command("exit\n");
easy.send_command("y\n");

Re: Help with scripting to HP Pro-curve

Expert
Posts: 18
18289     0

Hi Brian,

 

I see 2 things that may help, but not positive.  In Python, indentation is important.  The lines after the "With" statement should be indented.  Secondly, I have never needed to use a "\n" on the end of each easy.send_command.

 

Let me know if this helps.

 

-Lon.

Re: Help with scripting to HP Pro-curve

Superuser
Posts: 115
18289     0

This:

with NetMRIEasy(**defaults) as easy:
    easy.send_command("conf t");
    easy.send_command("password all");
    easy.send_command("new_op_pass");
    easy.send_command("new_op_pass");
    easy.send_command("new_mgr_pass");
    easy.send_command("new_mgr_pass");
    easy.send_command("exit");
    easy.send_command("exit");
    easy.send_command("y");
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Help with scripting to HP Pro-curve

Techie
Posts: 7
18289     0

ok, so we made a little progress with that. So now we are stuck on the interactive shell from the HP.

 

it stops as its waiting for the new password and then a return. 

 

sw-dr1-taperoom# no page

sw-dr1-taperoom# conf t

sw-dr1-taperoom(config)# password all

New password for Operator:  <- stuck here waiting. I think we might need to some how tell it that this is what is expected and then print the password variable $new_op_pass maybe?

 

 

Re: Help with scripting to HP Pro-curve

Superuser
Posts: 115
18289     0

Now add back this:

easy.send_command("new_op_pass\n");
easy.send_command("new_op_pass\n");
easy.send_command("new_mgr_pass\n");
easy.send_command("new_mgr_pass\n");

or this

easy.send_command("new_op_pass\n new_op_pass\n new_mgr_pass\n new_mgr_pass\n");
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Help with scripting to HP Pro-curve

Expert
Posts: 18
18289     0

There is a previous post that might have a solution for you.  Please see Interactive commands OR How to set a password in Junos.

 

The solution in there is for Perl, but I believe Python should have the same capabilities of using a second parameter.

 

Try:

 

easy.send_command("password all","New password for Operator:");
easy.send_command("new_op_pass");

 

I haven't tried this, but the other way is what Sif just posted, which should work to.

 

Re: Help with scripting to HP Pro-curve

Techie
Posts: 7
18289     0

Hi Lon,

 

So the procurves reply with an interactive shell. So when it asks me or 

 

New password for Operator:       <- I need to feed it the new password and hit enter. I thought the \n would tell it a new line was necessary which would get the switch to print out the next response which is

 

 

Please retype new password for Operator:   <- then i reprint the the new password again.

 

it just keeps getting stuck waiting for the password, so whateve I'm doing its not getting the password variable.

Re: Help with scripting to HP Pro-curve

Expert
Posts: 18
18289     0

If it got by the first prompt (you didn't say if it did or not), then try:

 

easy.send_command("password all","New password for Operator:");
easy.send_command("new_op_pass","Please retype new password for Operator:");
easy.send_command("new_op_pass");

Re: Help with scripting to HP Pro-curve

Techie
Posts: 7
18289     0

ok that worked so that last part is to exit out of each level

 

with NetMRIEasy(**defaults) as easy:
easy.send_command("conf t");
easy.send_command("password all", "New password for Operator:");
easy.send_command("new_op_pass", "Please retype new password for Operator:");
easy.send_command("new_op_pass", "New password for Manager:");
easy.send_command("new_mgr_pass", "Please retype new password for Manager: ");
easy.send_command("new_mgr_pass", "[A-Za-z0-9\-](config)# ");
easy.send_command("exit", "[A-Za-z0-9\-]# ");
easy.send_command("exit", "[A-Za-z0-9\-]> ");
easy.send_command("exit", "Do you want to log out [y/n]?");
easy.send_command("y");

 

My regex might be wrong?

 

Here is what is happenng:

 

 

sw-dr1-taperoom# conf t

sw-dr1-taperoom(config)# password all

New password for Operator: ***********

Please retype new password for Operator: ***********

New password for Manager: ************

Please retype new password for Manager: ************

sw-dr1-taperoom(config)#   <- it stops here

 

Thanks all. We are closer and I appreciate the help. We have multple models of procurves and if we get this one I can figure the rest of them similarly

 

 

 

Re: Help with scripting to HP Pro-curve

[ Edited ]
Expert
Posts: 18
18289     0

Prompt lines that terminate with "#", or ">" should automatically be caught by the send_command, so you shouldn't need to add regex for them. I removed the trailing space in the second parameter, not sure if that will make a difference, but it shouldn't be needed.

 

I also removed the ';' at the end of each line, the regular 'return' and indent the next line takes care of things.

 

Try:

 

with NetMRIEasy(**defaults) as easy:
    easy.send_command("conf t")
    easy.send_command("password all", "New password for Operator:")
    easy.send_command("new_op_pass", "Please retype new password for Operator:")
    easy.send_command("new_op_pass", "New password for Manager:")
    easy.send_command("new_mgr_pass", "Please retype new password for Manager:")
    easy.send_command("new_mgr_pass")
    easy.send_command("exit")
    easy.send_command("exit")
    easy.send_command("exit", "Do you want to log out \[y\/n\]\?")
    easy.send_command("y")

Re: Help with scripting to HP Pro-curve

Techie
Posts: 7
18289     0

Thank Lon. That did the trick. I do need the semi-colon at the end but that is a perl/netmri-ism it seems. Thanks again for your help. We have 500 of these switches and this was a life saver. 

Re: Help with scripting to HP Pro-curve

Expert
Posts: 18
18289     0

I thought this was Python Smiley Happy

It wasn't enough code to tell the difference between Perl and Python for me, lol

 

Glad it worked.

 

-Lon.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You