12-20-2023 01:10 PM
I wrote an EEM applet that runs the "show clock" CLI command, then tried to parse the output using the "action string range" statement. I wanted to get the 2 digit hour and 2 digit minute into two seperate varaibles. So I used something like:
action xxx string range $_cli_result 0 1
action xxx set hour $_string_result
action xxx string range $_cli_result 3 4
action xxx set minute $_string result
This didn't work however, as there appear to be some non-printing/control characters at the front of the string that caued the "string range" indexing not to work properly. In fact I couldn't get it to return the tens digit of the hour at all, I just kept getting what appeared on the screen as a blank character.
Does anyone know what's going on with the "show clock" command output? In the end, I ended up using the bult-in "$_event_pub_time" to get a useable timestamp string to parse. The problem with THAT method is that "$_event_pub_time" doesn't pay attention to the timezone in the configuration and always returns UTC time. So then I have to do math in EEM to get the correct time...
Solved! Go to Solution.
12-21-2023 08:57 AM
EEM aligns with TCL and the event_pub_time grabs this info from gettime() in linux. linux being the operating system and IOS-XE is a process. IOS-XE cli massages gettime() to a user configurable timezone if required but his does not change the underlying linux OS function. If you want the time to get reported by the specific timezone configured I believe you are on the right track by issuing "show clock" and the info can be parsed out by regexp rather than a string command.
event manager applet test
event none
action 010 cli command "enable"
action 030 cli command "show clock"
action 050 regexp "([0-9]+):([0-9]+):[0-9]+\.[0-9]+" "$_cli_result" match hour minute
action 060 puts "$hour:$minute"
INET#event manager run test
11:56
12-21-2023 08:57 AM
EEM aligns with TCL and the event_pub_time grabs this info from gettime() in linux. linux being the operating system and IOS-XE is a process. IOS-XE cli massages gettime() to a user configurable timezone if required but his does not change the underlying linux OS function. If you want the time to get reported by the specific timezone configured I believe you are on the right track by issuing "show clock" and the info can be parsed out by regexp rather than a string command.
event manager applet test
event none
action 010 cli command "enable"
action 030 cli command "show clock"
action 050 regexp "([0-9]+):([0-9]+):[0-9]+\.[0-9]+" "$_cli_result" match hour minute
action 060 puts "$hour:$minute"
INET#event manager run test
11:56
12-21-2023 12:10 PM
Thamks @Dan Frey! Can you please parse out & explain the regexp terms as I think that will be helpful for the community going forward (though it would be better if the “noise” wasn’t in the output in the first place. ;))
12-21-2023 09:40 AM
have you look at the sample script :
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