10-02-2017
09:32 AM
- last edited on
03-25-2019
02:37 PM
by
ciscomoderator
Hi Guys,
I trying to come up with a script that does the following:
1. runs a command to determine which interface the device is using as the default gateway i.e
Issue this command >>>show ip cef 0.0.0.0/0 | in nexthop
Outputs this>>>> nexthop 10.1.1.2 GigabitEthernet0/0
2. use a regular expression match to match "GigabitEthernet0/0" and set that result as a variable (result1)
3. use the previously set variable (result1) which stores the value "GigabitEthernet0/0" to issue another command to collect the ip address/mask information assigned to said interface and set that ip address information as another variable
4. have the script reconfigure the interface with vrf forwarding and resign the ip address back to the interface
I have not had success thus far and im looking for a bit of assistance..here is what i have so far
event manager applet VRF
event none
action 0000 cli command "enable"
action 0001 cli command "show ip cef 0.0.0.0/0 | in nexthop"
action 0002 regexp "\S+\Z" "$_cli_result" result1
action 0003 if $_regexp_result eq "1"
action 0004 cli command "show run interface $result1 | in address"
action 0006 set output2 "$_cli_result"
action 0008 cli command "config term"
action 0009 cli command "file prompt quiet"
action 0010 cli command "do copy running-config rollback.cfg"
action 0011 cli command "no file prompt quiet"
action 0012 cli command "interface $result1"
action 0013 cli command "ip vrf forwarding blah"
action 0014 cli command "$output2"
action 0098 cli command "end"
action 0099 end
debug output is the following:
*Oct 2 16:10:07.252: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router>
*Oct 2 16:10:07.252:
Router#%HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router>enable
*Oct 2 16:10:07.263: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 16:10:07.264: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router#show ip cef 0.0.0.0/0 | in nexthop
*Oct 2 16:10:07.374: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : nexthop 10.1.1.2 GigabitEthernet0/0
*Oct 2 16:10:07.375: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 16:10:07.377: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : CTL : cli_close called.
*Oct 2 16:10:07.388:
*Oct 2 16:10:07.388: tty is now going through its death sequence
Any assistance with figuring this one out would be great
10-02-2017 11:28 AM
I was able to figure out the issue with matching the interface name in the regexp...the below seems to work fine
event manager applet VRF
event none
action 0000 cli command "enable"
action 0001 cli command "show ip cef 0.0.0.0/0 | in nexthop"
action 0002 regexp "(Fa[^ ]+|Gi[^ ]+)+[0-9]" "$_cli_result" result1
action 0003 if $_regexp_result eq "1"
action 0005 cli command "show run interface $result1 | in address"
action 0006 set output2 "$_cli_result"
action 0007 end
action 0008 cli command "config term"
action 0009 cli command "file prompt quiet"
action 0010 cli command "do copy running-config rollback.cfg"
action 0011 cli command "no file prompt quiet"
action 0012 cli command "interface $result1"
action 0013 cli command "ip vrf forwarding blah"
action 0014 cli command "$output2"
action 0015 cli command "exit"
action 0016 cli command "do wr mem"
debug output
*Oct 2 18:23:46.450: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router>
*Oct 2 18:23:46.451: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router>enable
*Oct 2 18:23:46.461: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 18:23:46.462: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router#show ip cef 0.0.0.0/0 | in nexthop
*Oct 2 18:23:46.572: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : nexthop 10.1.1.2 GigabitEthernet0/0
*Oct 2 18:23:46.573: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 18:23:46.575: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router#show run interface GigabitEthernet0/0 | in address
*Oct 2 18:23:47.137: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : ip address 10.1.1.1 255.255.255.0
*Oct 2 18:23:47.138: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 18:23:47.139: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router#config term
*Oct 2 18:23:47.151: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Enter configuration commands, one per line. End with CNTL/Z.
*Oct 2 18:23:47.151: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:47.152: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config)#file prompt quiet
*Oct 2 18:23:47.262: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:47.263: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config)#do copy running-config rollback.cfg
*Oct 2 18:23:51.760: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : 4525 bytes copied in 4.361 secs (1038 bytes/sec)
*Oct 2 18:23:51.760: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT :
*Oct 2 18:23:51.761: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:51.762: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config)#no file prompt quiet
*Oct 2 18:23:51.872: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:51.873: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config)#interface GigabitEthernet0/0
*Oct 2 18:23:51.984: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config-if)#
*Oct 2 18:23:51.985: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config-if)#ip vrf forwarding blah
*Oct 2 18:23:52.150: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : % VRF blah not configured
*Oct 2 18:23:52.150: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config-if)#
*Oct 2 18:23:52.151: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config-if)# ip address 10.1.1.1 255.255.255.0
*Oct 2 18:23:52.152: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router#
*Oct 2 18:23:52.262: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config-if)#
*Oct 2 18:23:52.263: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config-if)#
*Oct 2 18:23:52.263: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router#
*Oct 2 18:23:52.264: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : ^
*Oct 2 18:23:52.265: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : % Invalid input detected at '^' marker.
*Oct 2 18:23:52.265: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT :
*Oct 2 18:23:52.266: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config-if)#
*Oct 2 18:23:52.266: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config-if)#exit
*Oct 2 18:23:52.278: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:52.279: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : Router(config)#do wr mem
Router#
*Oct 2 18:23:54.218: %GRUB-5-CONFIG_WRITING: GRUB configuration is being updated on disk. Please wait...
*Oct 2 18:23:55.007: %GRUB-5-CONFIG_WRITTEN: GRUB configuration was written to disk successfully.
Router#
*Oct 2 18:23:55.068: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Building configuration...
*Oct 2 18:23:55.069: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : [OK]
*Oct 2 18:23:55.069: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Router(config)#
*Oct 2 18:23:55.070: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : CTL : cli_close called.
10-02-2017 01:17 PM
Spoke too soon....I tried running the script on a router that has serial interfaces and the ran into this issue:
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : CTL : cli_open called.
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01>
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : epc-remotesite1-r01>enable
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01#
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : epc-remotesite1-r01#show ip cef 0.0.0.0/0 | in nexthop
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : nexthop x.x.x.x Serial0/0/0.1
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01#
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : epc-remotesite1-r01#show run interface Serial0/0/0.1
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : epc-remotesite1-r01 | in address
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Building configuration...
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT :
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : Current configuration : 169 bytes
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : !
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : interface Serial0/0/0.1 point-to-point
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : description AT&T MPLS
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : ip address x.x.x.x 255.255.255.252
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : ip wccp 62 redirect in
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : frame-relay interface-dlci 777
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : end
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT :
Oct 2 15:02:46 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01#
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : IN : epc-remotesite1-r01#config term
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01#
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01 | in address
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : ^
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : % Invalid input detected at '^' marker.
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT :
Oct 2 15:02:51 CDT: %HA_EM-6-LOG: VRF : DEBUG(cli_lib) : : OUT : epc-remotesite1-r01#
Oct 2 15:02:51 CDT:
the command action 0005 cli command "show run interface $result1 | in address" is not being completely entered...the command is being chopped off after the $result1 so the " | in address " part is not be running to shorten the command to only include the ip address of the interface in question
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide