Execute CLI commands with prompts in EEM
In response to my post about combining Tcl shell with EEM to get around the “no prompts” limitation of EEM action cli command, Xavier proposed using the undocumented pattern option of the action cli command, which changes the string the EEM script is expecting to indicate that the current command has been executed.
By default, the EEM action cli command waits until it receives exec-level prompt from the VTY (Router> or Router#), resulting in an endless wait and aborted EEM applet in IOS release 12.4(15)T (earlier releases would hang a VTY line forever) if a CLI command returns an additional prompt. With the pattern option, you can change the expected reply to whatever prompt the CLI command is outputting. For example, to clear interface counters, you could use the following EEM applet:
By default, the EEM action cli command waits until it receives exec-level prompt from the VTY (Router> or Router#), resulting in an endless wait and aborted EEM applet in IOS release 12.4(15)T (earlier releases would hang a VTY line forever) if a CLI command returns an additional prompt. With the pattern option, you can change the expected reply to whatever prompt the CLI command is outputting. For example, to clear interface counters, you could use the following EEM applet:
event manager applet testWhen it's executed with the event manager run test command and the event manager CLI debugging is enabled, you'll see the following printout:
event none
action 0.9 cli command "enable"
action 1.0 cli command "clear counter loopback 0" pattern "confirm"
action 1.1 cli command "y"
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : CTL : cli_open called.
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT :
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : R1>
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN : R1>enable
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT :
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : R1#
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN : R1#clear counter loopback 0
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN : y
%CLEAR-5-COUNTERS: Clear counter on interface Loopback0 by on vty0 (EEM:test)
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : y
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : R1#
%HA_EM-6-LOG: test : DEBUG(cli_lib) : : CTL : cli_close called.
c2821(config-applet)#action 2.0 cli command "copy flash:testsla running-config" pattern "running-config"
^
% Invalid input detected at '^' marker.
c2821#sh ver
...
System image file is "flash:c2800nm-adventerprisek9-mz.124-2.T1.bin"
Router(config-applet)#action 1.0 cli command "clear counters se1/0" pattern
^
% Invalid input detected at '^' marker.
Doesn't like the 'pattern' keyword. What IOS version supports 'pattern'?
I always try to mention the release when a feature I'm writing about was first introduced based on CCO IOS documentation. I also believe writing about other exciting features is worth more than doing reverse-engineering to figure out in which IOS release Cisco introduced undocumented features ... and I really appreciate the release-specific comments you're making, as they help us all figure out approximately when these beasts were coded.