I'm hoping someone can point me in the correct direction. I am trying use EEM to detect with a USB flash drive is plugged into a router and subsequently write a default config to the device. When I use the syslog detector I always recieve an error stating the "dir" command is sending invalid input. When I run the script manually I do not recieve any errors. Is there some difference between the syslog detector and the none detector?
Thanks in advance.
Nov 30 15:20:51.923 CST_: %USBFLASH-5-CHANGE: usbflash0 has been inserted!
Nov 30 15:20:51 CST_: %HA_EM-6-LOG: USB_Reset: Checking for new config.
Nov 30 15:20:51 CST_: %HA_EM-6-LOG: USB_Reset: USB Drive found usbflash0
When you plug in the device are you able to do "dir usbflash0:" manually? There should be no difference in this action between the none and syslog events, as long as usb_drive is set to the same value. You may want to try printing the $usb_drive value first with other characters around it to ensure nothing is hidden. Something like --$usb_drive--
Thanks for the response. I did verify that manually doing a sh usbflash0: works as expected. I also did a debug to determine exactly where the command was failing and was able to cofirm that the command did not like the usbflash0:. I believe that I am running into a race condition where the syslog message is being sent but the filesystem on the flash isn't ready and available. I worked around the problem by doing a sh run cli command in the script. This delays the script long enough so that the dir command succeeds.
Router(config-applet)#action 1.0 wait ?
<1-31536000> Seconds value
That is (hopefully) more deterministic and forces the device to wait a specified amount of time. Looking at the usb device insertion source code the syslog message for USB device insertion is printed before actually setting up the file system. So the behavior you see actually makes sense in a way for a lightly loaded device but I don't think it is 100% certain that any of these workarounds will work in every situation.
The proper way for EEM trigger policies on USB device insertion is to have a "USB device insertion and removal event detector" built specifically into IOS that - for insertion - runs *AFTER* the USB device is up and after all of the platform specific USB device items have been taken care of. I don't know if there are any plans to implement such a thing though. Until such an event detector exists, this sort of policy might be problematic in certain situations. It may work in your specific situation but may not work in others or on other platforms.