06-28-2016 11:00 AM
I'm having some issues with escaping variables in EEM actions. I'm not sure exactly how to escape them properly, as there doesn't seem to be a whole lot of documentation on this. Essentially I need to define a variable which can be called in a cli action.
I've tried defining a variable with
event manager environment TIME "show clock"
I've tried defining it with IOS.sh shell variables and calling those in an action, but it doesn't escape properly. For example,
action 1.0 set TIME "show clock"
action 2.0 syslog msg "$TIME"
Does not display the information I want (it actually just sends a blank line to the syslog).
06-28-2016 01:39 PM
I've also now tried to simply do a
action 1.0 cli command "show clock"
action 2.0 append flash:test.txt $_cli_result
To which I get nothing. I don't think I'm calling these variables correctly, as when I see the debugs run by it doesn't print anything except a blank line.
06-28-2016 01:49 PM
So I found another thread detailing exactly what I'm trying to do:
https://supportforums.cisco.com/discussion/11024946/eem-variable-show-command-output-and-create-filename
So I copy/pasted the config, hoping to get something that may work:
event manager applet test
event none
action 10 cli command "en"
action 20 cli command "sh clock"
action 21 regexp "([0-9]+).*" "$_cli_result" match hour
action 22 regexp ".*\[0-9]+):.*" "$_cli_result" match minute
action 23 regexp ".*\.([0-9]+).*" "$_cli_result" match msec
action 25 set result "TEST-IPT-GT-$hour$minute$msec"
action 30 set filename "$result.txt"
action 40 cli command "sh clock | append flash:$filename"
action 90 cli command "exit"
Except when reviewing a modified config, I get the following:
event manager applet test
event none
action 10 cli command "en"
action 20 cli command "sh clock"
action 21 regexp "([0-9]+).*" "" match hour
action 22 regexp ".*[0-9]+):.*" "" match minute
action 23 regexp ".*.([0-9]+).*" "" match msec
action 25 set result "TEST-IPT-GT-"
action 30 set filename ".txt"
action 40 cli command "sh log | redirect ftp://10.10.10.10/"
action 90 cli command "exit"
All the variables are missing. If I try to run the script, it dies with the following debugs:
Jun 28 13:44:58.876 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN : sea-test-01#en
Jun 28 13:44:58.876 PDT: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Jun 28 13:44:58.876 PDT: eem_no_scan flag set, skipping scan of command_string=enable
Jun 28 13:44:58.886 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : sea-test-01#
Jun 28 13:44:58.886 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : IN : sea-test-01#sh clock
Jun 28 13:44:58.886 PDT: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Jun 28 13:44:58.886 PDT: eem_no_scan flag set, skipping scan of command_string=show clock
Jun 28 13:44:58.897 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : 13:44:58.886 PDT Tue Jun 28 2016
Jun 28 13:44:58.897 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : OUT : sea-test-01#
Jun 28 13:44:58.897 PDT: %HA_EM-6-FMPD_REGCOMP: Error compiling regular expression: *** unknown regexp error code ***
Jun 28 13:44:58.897 PDT: %HA_EM-3-FMPD_ERROR: Error executing applet test statement 22
Jun 28 13:44:58.897 PDT: %HA_EM-6-LOG: test : DEBUG(cli_lib) : : CTL : cli_close called.
I'm running EEM version 4.0 on IOS XE 03.16.02.S.
06-28-2016 03:41 PM
Even a very simple
event manager applet tester
event none
action 1.0 set var "TEST123"
action 2.0 syslog msg "$var"
gives me nothing back.
06-29-2016 08:01 AM
This was due to enabing IOS.sh via
terminal shell
terminal shell trace
conf t
shell processing full
end
Disable shell and remove shell processing full from your running-config. IOS.sh treats all $ characters as variables it interprets, which stops processing of EEM variables.
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