Highlighted
saj_g
Visitor.
1966 views

Bat Script to Change Config on HP Switch

Hi All,

I am trying to make a script to do changes on network switches, using simple bat scripts.

I just tried -( plink.exe -ssh user@host -pw xxxx -m c:\command.txt ) but I am not sure about the commands which I need to use on command.txt to run on HP switch terminal. I can ssh to my network switch but that leaves me at the switch's CLI prompt.

But what I want to do is to be able to script commands to be executed by the switch, like change vlan or add vlan etc. 

Are there instructions on how to do something simple list this in a script?

Log into the switch then enter to system-view and change vlan of a particular interface, or Pass one or more commands test the return code to see if there was an error with the passed commands then save the config and log off the switch.

Thanks.

Saj

Tags (2)
0 Likes
2 Replies
Micro Focus Expert
Micro Focus Expert

Re: Bat Script to Change Config on HP Switch

HI @saj_g,

one way is doing what is in this KM Document:

http://support.openview.hp.com/selfsolve/document/KM00448875

 

if you can't see it here is an extract:

From the NA GUI:

Menu: Devices -> Inventory

Select a device for which you would like to create a script.

On the Device Page, below the yellow section on the page, select Menu: Connect -> Via Proxy Using SSH.

NA will connect to the device.

In the API window the user can run a couple of commands on the device (i.e. show running-config or show users).

Once commands are done being entered into the API, please exit the API.

Back on the Device Page, below the yellow section on the page, select Menu: View -> Telnet/SSH Sessions.

A list of Device Sessions will appear on the lower section of the Device Page.

 

The user can select the one just created in the API with the link to the right: View Full Telnet/SSH Session

Once on the Telnet/SSH Session page select the link near the upper right-hand corner of the page Convert to Perl Script.

NA will open the New Command Script page, which will allow the user to edit the content of the now converted Perl script. 

Here’s an example:

#!/usr/bin/perl

use strict;

use warnings;

use Getopt::Long;

use Opsware::NAS::Connect;

my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');

my $device = '#$tc_device_id$';

my @output;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port);

$con->login();

$con->connect( $device ) or die "Failed to connect.";

$con->cmd("terminal length 0");

print "show running\n";

@output = $con->cmd("show running"); 

print join("\n", @output);

print "show users\n";

@output = $con->cmd("show users");

print join("\n", @output);

@output = $con->disconnect();

$con->logout();

undef $con;

exit(0);

 The output in the NA created script is always in @output so the user can always save it to a variable of his/her choice for further manipulation as s/he expands and creates his/her own script from this convenient template.

And then save the script.

 

Pedro A. Batista
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the THUMB at the bottom left of the post and show your appreciation.
0 Likes
saj_g
Visitor.

Re: Bat Script to Change Config on HP Switch


@Pedro_B_NAwrote:

HI @saj_g,

one way is doing what is in this KM Document:

http://support.openview.hp.com/selfsolve/document/KM00448875

 

if you can't see it here is an extract:

From the NA GUI:

Menu: Devices -> Inventory

Select a device for which you would like to create a script.

On the Device Page, below the yellow section on the page, select Menu: Connect -> Via Proxy Using SSH.

NA will connect to the device.

In the API window the user can run a couple of commands on the device (i.e. show running-config or show users).

Once commands are done being entered into the API, please exit the API.

Back on the Device Page, below the yellow section on the page, select Menu: View -> Telnet/SSH Sessions.

A list of Device Sessions will appear on the lower section of the Device Page.

 

The user can select the one just created in the API with the link to the right: View Full Telnet/SSH Session

Once on the Telnet/SSH Session page select the link near the upper right-hand corner of the page Convert to Perl Script.

NA will open the New Command Script page, which will allow the user to edit the content of the now converted Perl script. 

Here’s an example:

#!/usr/bin/perl

use strict;

use warnings;

use Getopt::Long;

use Opsware::NAS::Connect;

my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');

my $device = '#$tc_device_id$';

@My @output;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port);

$con->login();

$con->connect( $device ) or die "Failed to connect.";

$con->cmd("terminal length 0");

print "show running\n";

@output = $con->cmd("show running"); 

@print join("\n", @output);

print "show users\n";

@output = $con->cmd("show users");

@print join("\n", @output);

@output = $con->disconnect();

$con->logout();

undef $con;

exit(0);

@ The output in the NA created script is always in @output so the user can always save it to a variable of his/her choice for further manipulation as s/he expands and creates his/her own script from this convenient template.

And then save the script.

 



@Pedro_B_NAwrote:

HI @saj_g,

one way is doing what is in this KM Document:

http://support.openview.hp.com/selfsolve/document/KM00448875

 

if you can't see it here is an extract:

From the NA GUI:

Menu: Devices -> Inventory

Select a device for which you would like to create a script.

On the Device Page, below the yellow section on the page, select Menu: Connect -> Via Proxy Using SSH.

NA will connect to the device.

In the API window the user can run a couple of commands on the device (i.e. show running-config or show users).

Once commands are done being entered into the API, please exit the API.

Back on the Device Page, below the yellow section on the page, select Menu: View -> Telnet/SSH Sessions.

A list of Device Sessions will appear on the lower section of the Device Page.

 

The user can select the one just created in the API with the link to the right: View Full Telnet/SSH Session

Once on the Telnet/SSH Session page select the link near the upper right-hand corner of the page Convert to Perl Script.

NA will open the New Command Script page, which will allow the user to edit the content of the now converted Perl script. 

Here’s an example:

#!/usr/bin/perl

use strict;

use warnings;

use Getopt::Long;

use Opsware::NAS::Connect;

my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$');

my $device = '#$tc_device_id$';

@My @output;

my $con = Opsware::NAS::Connect->new(-user => $user, -pass => $pass, -host => $host, -port => $port);

$con->login();

$con->connect( $device ) or die "Failed to connect.";

$con->cmd("terminal length 0");

print "show running\n";

@output = $con->cmd("show running"); 

@print join("\n", @output);

print "show users\n";

@output = $con->cmd("show users");

@print join("\n", @output);

@output = $con->disconnect();

$con->logout();

undef $con;

exit(0);

@ The output in the NA created script is always in @output so the user can always save it to a variable of his/her choice for further manipulation as s/he expands and creates his/her own script from this convenient template.

And then save the script.

 


Thanks Pedro for the quick response, I am a kid in perl scripting , I will try this method and update you soon.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.