Thursday, January 23, 2014

First EEM Applet - Autobackup to USB stick on a Cisco Router

Although, I've been scripting for a long time, I have not ever used the EEM and TCL features on Cisco devices to run a script on the device itself.  This is the first script that I've written that uses the embedded event manager applet features.  When "usbflash0:" is inserted into the router it will backup a copy of the running configuration to the filename HOSTNAME.txt.DATE.

Here is the script:

!Tested with a Cisco 1841 running 15.1T Advanced Enterprise Services.
file prompt quiet
event manager applet BACKUP-TO-USB
 event syslog pattern "usbflash0 has been inserted"
 action 10.000 cli command "enable"
 action 10.010 cli command "show clock"
 action 10.020 set month "none"
 action 10.030 set day "none"
 action 10.040 set year "none"
 action 10.050 set result "none"
 action 10.060 regexp "([A-Z][a-z][a-z]) ([0-9]+) ([0-9][0-9][0-9][0-9])" "$_cli_result" result month day year
 action 10.070 set hostname "hostname"
 action 10.080 cli command "show running-config | i hostname"
 action 10.090 regexp "hostname ([A-Za-z0-9._-]+)" "$_cli_result" result hostname
 action 20.000 cli command "copy system:running-config usbflash0:$hostname.txt.$month-$day-$year"
 action 99.999 exit


It works by scheduling the event to run whenever the log receives a message that usbflash0 has been inserted.  It will then parse the data from the show clock command and save the running configuration to the USB stick.  I had to run the global setting "file prompt quiet" to turn off extra prompting that verifies the destination file name; I'm sure this could be worked out but it was just a fun exercise and not something I planned on using in production.

No comments:

Post a Comment