cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5337
Views
0
Helpful
5
Replies

EEM variable for show command output and create a filename

Gerard Gacusan
Level 1
Level 1

I'm configuring EEM applet, example CPU High event. When it triggers the event, action is "show tech | redirect tftp://x.x.x.x/showtechoutput". The EEM event is working fine and triggered the show tech output into the tftp server. My question is, i'd like to add maybe date/time in the filename so it will not overwrite the file everytime there is a triggered event.

The EEM event variable i'm seeing in doc is "_event_pub_sec" but it won't work when i add after or before the filename. any idea?

thanks in advance ...

5 Replies 5

Joe Clarke
Cisco Employee
Cisco Employee

Adding $_event_pub_sec to the end of the filename should work:

action 1.0 "show tech | redirect tftp://x.x.x.x/showtech.$_event_pub_sec"

That said, TFTP is very particular about how files can be created.  Typically, a TFTP server will require the file to exist before a remote host can copy to it.  If the filename changes each second, this will not work.  Using a protocol like FTP or SCP may work better.

Hi Gerard, did you able to solve this issue?
I am also looking for creating variable filename through eem. Although script below gives correct output from "puts" command, it does not create file:

 action 20 cli command "sh clock"
 action 30 set string "$_cli_result"
 action 60 set filename "$_string_result.txt"
 action 65 puts "$filename"
 action 70 cli command "sh clock | append flash:file.$_filename"
 

In order to write to a file you need to enable the applet.  You're missing:

 

action 10 cli command "enable"

 

Your variable is also wrong.  You need:

 

action 70 cli command "show clock | append flash:file.$filename

 

Finally, not all filesystems support "append" so make sure you can run a similar command manually.

I did not include all actions for short post, we have "enable" command as first action.
In action 70 , $filename or $_filename  does not create file with that name. However regex seems working, below commands worked as expected:

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"
 

Thanks&Regards.

You don't need action 90.  You should also enable "debug event manager action cli" and re-run your test.  The output will show why the append command is failing.

Review Cisco Networking for a $25 gift card