I'm used to the Juniper and Extreme worlds more than Cisco. I'm able to get by OK, but some basic cli issues arise that have finally frustrated me enough.
Inside a Cisco ASA 5505/5510 running 8.3+ or a Cisco 2901 router running 15.2.
Technically with IOS 15.2, the answer is "yes, you can know what interface you're configuring" but admittedly my solution involves a rather unpleasant kludge-fix.
I will demonstrate how to use EEM version 3.2 to print out the interface name that you last configured. I do not pretend this solution is perfect, but it gets the job done.
Example:
DEN-EDGE-02#sh ver | i IOS
Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M7, RELEASE
SOFTWARE (fc2)
DEN-EDGE-02#
DEN-EDGE-02#conf t
Enter configuration commands, one per line. End with CNTL/Z.
DEN-EDGE-02(config)#username cisco password cisco
DEN-EDGE-02(config)#
DEN-EDGE-02(config)#interface Fa0/0
Last interface configured was: FastEthernet0/0
DEN-EDGE-02(config-if)#no ip proxy-arp
Last interface configured was: FastEthernet0/0
DEN-EDGE-02(config-if)#interface lo0
Last interface configured was: Loopback0
DEN-EDGE-02(config-if)#ip address 1.1.1.1 255.255.255.255
Last interface configured was: Loopback0
DEN-EDGE-02(config-if)#exit
Last interface configured was: Loopback0
DEN-EDGE-02(config)#
DEN-EDGE-02(config)#username cisco password cisco
Last interface configured was: Loopback0
DEN-EDGE-02(config)#end
DEN-EDGE-02#
DEN-EDGE-02#sh ver | i IOS
Cisco IOS Software, 2800 Software (C2800NM-ADVENTERPRISEK9-M), Version 15.1(4)M7, RELEASE
SOFTWARE (fc2)
DEN-EDGE-02#
At this point, my answer is closer to proof-of-concept code, which has several caveats...
- Interface logging happens even after exiting interface configuration sub-mode; thus you will be reminded about what interface you recently configured as long as you're still in any Cisco IOS configuration mode. The EEM policy silences itself after exiting config mode with
end
- but it doesn't catch exit via cntl-z
at this point.
- EEM configures the router to store script state variables (i.e.
$_user_intf
and $_config_mode
). This means you get %SYS-5-CONFIG_I
syslog messages each time the script changes state (which is quite annoying if you're on the console). Technically you could glue in an ESM policy to silence the EEM syslog messages, but that only increases the work you're doing to solve this problem...
Please find the configuration to print the last configured interface below... I need to give credit to Ivan Pepelnjak for his blog about _exit_status
! Reset to defaults...
no event manager applet IntfCliLog
no event manager environment _user_intf
no event manager environment _config_mode
!
event manager environment _user_intf _None_
event manager environment _config_mode 1
event manager applet IntfCliLog
event cli pattern ".*" sync yes
action 010 set match "_None_"
action 020 regexp "^(configure t)" $_cli_msg match
action 030 comment !! Set _config_mode upon entering config mode
action 040 if $match ne "_None_"
action 050 cli command "enable"
action 060 cli command "configure t"
action 070 cli command "event manager environment _config_mode 1"
action 080 cli command "end"
action 090 end
action 100 set match "_None_"
action 110 regexp "^(end)" $_cli_msg match
action 120 comment !! clear variables upon exit from config mode
action 130 if $match ne "_None_"
action 140 cli command "enable"
action 150 cli command "configure t"
action 160 cli command "event manager environment _config_mode 0"
action 170 cli command "event manager environment _user_intf _None_"
action 180 cli command "end"
action 190 end
action 200 comment !! Parse any "interface" commands
action 210 set intfName "_None_"
action 220 regexp "^interface *(.*)" $_cli_msg match intfName
action 230 if $intfName ne "_None_"
action 240 cli command "enable"
action 250 cli command "configure t"
action 260 cli command "event manager environment _user_intf $intfName"
action 270 cli command "end"
action 280 end
action 290 comment !! Log the last interface configured
action 300 if $_config_mode eq 1
action 340 if $_user_intf ne "_None_"
action 350 puts "Last interface configured was: $_user_intf"
action 360 end
action 370 end
action 380 comment !! Set _exit_status 1 to run commands with "event cli ... sync yes"
action 390 set _exit_status 1
action 400 exit