- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Help with scripting to HP Procurve
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 01:54 PM
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 ***
Solved! Go to Solution.
Re: Help with scripting to HP Procurve
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 02:03 PM
Can you post the script and remove the new password?
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Help with scripting to HP Procurve
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 09:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 09:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 09:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 09:42 AM
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");
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Help with scripting to HP Pro-curve
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 12:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 01:09 PM
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");
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Help with scripting to HP Pro-curve
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 01:14 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 01:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 01:30 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 02:08 PM
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 ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2019 02:26 PM - edited 04-03-2019 02:26 PM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2019 05:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2019 08:35 AM
I thought this was Python
It wasn't enough code to tell the difference between Perl and Python for me, lol
Glad it worked.
-Lon.