cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1988
Views
5
Helpful
4
Replies

Does EEM support "catching" non executed commands?

ndarkness
Level 1
Level 1

Hello, I was wondering if EEM does support catching error or exceptions. I mean, I would use EEM to copy a file to my ftp server, however if for any reason my ftp server is down, I don´t want that my cisco keeps the that file, instead of that I would rather delete it. Is it possible to check inside the EEM whether the execution was successful or not, and then launch the command that will delete the file?

event timer watchdog name dataGather time 900

action 1.0 cli command "enable"

action 2.0 cli command "term length 0"

action 2.1 cli command "config term"

action 2.2 cli command "file prompt quiet"

action 3.0 cli command "show interface vlan 1 | append flash:vlan1I.txt"

action 4.0 cli command "copy flash:vlan1I.txt ftp://myFTPServer/vlan1I.txt "

action 5.0 ????

action 6.1 cli command "config term"

action 6.2 cli command "no file prompt quiet"

Thanks in advance,

Regards

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

Check the command output stored in the $_cli_result variable.  For example:

action 5.0 regexp "Error" $_cli_result

action 5.1 if $_regexp_result eq 1

action 5.2  puts "ERROR OCCURRED; handle me"

action 5.3 end

This assumes the word, "Error" appears in your error.  You'd want to adjust the pattern for the specific error messages you actually see.

Something like this may be correct?

event timer watchdog name dataGather time 900

action 1.0 cli command "enable"

action 2.0 cli command "term length 0"

action 2.1 cli command "config term"

action 2.2 cli command "file prompt quiet"

action 3.0 cli command "show interface vlan 1 | append flash:vlan1I.txt"

action 4.0 cli command "copy flash:vlan1I.txt ftp://myFTPServer/vlan1I.txt "

action 5.0 regexp "Error" $_cli_result

action 5.1 if $_regexp_result eq 1

action 5.2  cli command "delete flash:vlan1I.txt" pattern "confirm"

action 5.3 cli command "y"

action 5.4 end

action 6.1 cli command "config term"

action 6.2 cli command "no file prompt quiet"


I remember that when you try to send something to the ftp server and that one is unavailable, it does retrieve some "Error ftp...."

This looks okay, except I'm not really sure of your login.  Do you really want to delete the file when the transfer FAILS?  It would seem to me you'd rather keep the file until the transfer is successful, and then delete it.

Hi Joseph,

I know what you mean, but the point is that I have to use the command append to redirect the output of show to the file, since I have tested with redirect and it isn't working. Then, as append can create a huge file, I prefer deleting the file if the transfer to ftp server is unsuccessful than keeping it "growing up"  in my cisco which might lead to an deplexion of memory on it.

Likewise, if the transfer was successful I will delete it afterwards.

regards