- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-07-2015 11:37 AM
I am trying to remove port-security commands from a Cisco Switch. The interface commands on a typical switch look like the following:
interface GigabitEthernet0/1
switchport access vlan 32
switchport trunk encapsulation dot1q
switchport mode access
switchport voice vlan 34
switchport port-security maximum 4
switchport port-security violation restrict
switchport port-security aging time 1
switchport port-security aging type inactivity
switchport port-security
spanning-tree portfast
spanning-tree bpduguard enable
end
I wish to remove all the commands in RED. I am utilizing the Regular Expression Test, to correctly define my Trigger-Variables and Trigger-Templates.
They are defined as:
Trigger-Variables
$cmdattrbs string
Trigger-Template
switchport port-security [[$cmdattrbs]]
Upon executing the test, it grabs the 1st 4 lines correctly, but the 5th line "switchport port-security" matches the cmdattrbs of the next line "spanning-tree portfast", which is not the desired outcome. Is there a way to match a line with no attributes after "switchport port-security"?
Solved! Go to Solution.
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-07-2015 12:08 PM
I modified the Trigger-Variables and Templates to the following and this seems to capture the 5 lines I am looking for. Not sure if there is a better way.
Trigger-Variables
$cmdattrbs /maximum\s\d{1,2}|violation\srestrict|aging\stime\s\d{1,2}|aging\stype\sinactivity|\s/
Trigger-Template
switchport port-security [[$cmdattrbs]]
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-07-2015 12:37 PM
|
|
|
|
|
|
|
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-07-2015 01:11 PM
Appreciate your post and the amount of information/context you provided. I'll ensure this gets routed to the right folks!
Eric
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-08-2015 04:24 AM
Mark,
Trigger-Varriables:
$test string
Trigger-Template:
switchport port-[[$test]]
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Remove Multiple Commands from Interfaces
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-08-2015 11:41 AM - edited 12-08-2015 11:42 AM
Thank you Sif. I am still having trouble executing the loop in a streamlined fashion. I want to do the following:
1. Go into Configuration Mode 1 time for each switch - config t
2. Go into the interface 1 time and then execute the removal of the 5 switchport port-security commands.
3. Then end out of configuration mode - end
4. Save the config.
My trials have me going in and out of config mode and specifying the interface before each removal command. Is there a better way to do this My script I have at the moment is below. Any help would be appreciated.
===============
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:
sho run interface $intName
Output-Triggers:
ParseOutput
################
Trigger:
ParseOutput
Trigger-Variables:
$cmdattrbs string
Trigger-Template:
switchport port-[[$cmdattrbs]]
Trigger-Commands: {$UpdateMade eq "no"}
DEBUG:config t
DEBUG:int $intName
SET:$UpdateMade = "yes"
Trigger-Commands: {$UpdateMade eq "yes"}
DEBUG:no switchport port-$cmdattrbs
########
Action:
End and Write Memory
Action-Description:
End and Write Memory only if we entered config mode.
Action-Commands:{$UpdateMade eq "yes"}
DEBUG:end
DEBUG:write mem
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-09-2015 09:57 AM
Look at Example5.ccs -- it does exactly what you want by using the $UpdateMade variable.
The only change that I would recommend is to send "end" instead of "exit". If the series of config commands cause the parser to enter a sub-command mode (e.g., interface xxx), "exit" will back out one level to global mode, whereas "end" will leave config mode entirely.
Re: Remove Multiple Commands from Interfaces
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
12-09-2015 10:22 AM
Sif,
I've not seen matches continue into the next line of output as mthiel117 observed. Since Ruby regexp supposedly enables multi-line mode by default, I inferred that the underlying Perl code for CCS implicitly applies an end-of-line ($) to the complete match pattern line in a template. Not true?
- Marty