Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

Network Change & Configuration Management

Reply
Highlighted
Accepted Solution

Cisco - Make Changes on Multiple Interfaces and Save Config

Authority
Posts: 20
5005     0

I am looking for a script example of how to make change across multiple interfaces and then save the changes once completed.  

 

I am looking to do something like the following:

 

config t

 

int gi0/1

  no switchport port-security

  no switchport voice vlan 30

 

int gi0/2

  

  no switchport port-security

  no switchport voice vlan 30

 

...  repeat for every port on the switch

 

end

 

write memory

 

=============

 

I am have trouble figuring out how to go int to configuration mode 1 time, iterate through all the interfaces and then finally end out and save the configuration before moving on to the next switch.

 

Questions:

 

1.  Are there any templated scripts that can do such a task?

2.  Should this be done in CCS or Perl?

 

Thanks ahead of time.

 

 

Highlighted

Re: Cisco - Make Changes on Multiple Interfaces and Save Config

Expert
Posts: 236
5006     0

NetMRI ships with a collection of sample scripts that incrementally show how to do exactly what you want.  Both CCS and Perl equivalents are included.  Start with Example5.ccs or Example5.pl.

Highlighted

Re: Cisco - Make Changes on Multiple Interfaces and Save Config

Authority
Posts: 20
5006     0

Thank you MAdkins.  Those scripts look promising.

Highlighted

Re: Cisco - Make Changes on Multiple Interfaces and Save Config

Techie
Posts: 6
5006     0

If you want to make the same changes to all interfaces and if the switch is Cisco why not use an interface range and change them all at once ? Heck you could do that with an ad hoc script quite easily.

 

Int range gi 0/1-48

no switchport port-security

  no switchport voice vlan 30

do wr mem

 

 

Highlighted

Re: Cisco - Make Changes on Multiple Interfaces and Save Config

Authority
Posts: 20
5006     0

BGroves, then the issue becomes how many line cards does a chassis have to formulate the correct range.

Highlighted

Re: Cisco - Make Changes on Multiple Interfaces and Save Config

Authority
Posts: 20
5006     0

Here is my final script to remove port security off every interface on a switch.  This seems to be a useble solution.

 

Script-Filter:
$Vendor eq "Cisco" and $Type in ["Switch","Switch-Router"] and $sysDescr like /IOS/

################

Action:
Find Interfaces

Action-Commands:
SET: $UpdateMade = "no"
sho ip int brief

Output-Triggers:
Process Interfaces

################
Trigger:
Process Interfaces

Trigger-Description:
Find valid interfaces to check for helpers - An interface that has an ip address and is "up"

Trigger-Variables:
$IntName /(\w+\d+(\/\d{1,2}|\/\d{1,2}\/\d+|\/\d{1,2}\.\d+|\/\d{1,2}\:\d+)?|\w+-\w+\d{1,3})/

Trigger-Template:
[[$intName]]\s+unassigned

Trigger-Commands: {$UpdateMade eq "no"}
show run interface $intName
SET:$cmdsRemoved = "no"

Trigger-Commands: {$UpdateMade eq "yes"}
do show run interface $intName
SET:$cmdsRemoved = "no"

Output-Triggers:
ParseOutput
################
Trigger:
ParseOutput

Trigger-Variables:
$cmd /switchport\sport-security\smaximum|switchport\sport-security\sviolation\srestrict|switchport\sport-security\saging\stime|switchport\sport-security\saging\stype|switchport\sport-security/

Trigger-Template:
[[$cmd]]

Trigger-Filter:
$cmd like /port-security/

Trigger-Commands: {$UpdateMade eq "no"}
config t

# Only remove the commands 1 time, not for each match of "port-security"

Trigger-Commands: {$cmdsRemoved eq "no"}
int $intName
no switchport port-security maximum
no switchport port-security violation restrict
no switchport port-security aging time
no switchport port-security aging type inactivity
no switchport port-security
exit
SET:$UpdateMade = "yes"
SET:$cmdsRemoved = "yes"

 


########
Action:

End and Write Memory

Action-Description:
End and Write Memory only if we entered config mode.

Action-Commands: {$UpdateMade eq "yes"}
end
write mem
SET:$UpdateMade = "no"

 

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You