cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2170
Views
0
Helpful
4
Replies

Trying to get a TCL script to execute within a Cisco EEM (cronjob based)

j.loduca
Level 1
Level 1

There are probably better ways to accomplish this on a Cisco. My attempt here is to set up a simple cronjob in a router to execute a TCLSH script once per day.  THe TCL script works fine. All it does is find the hostname of my router, then assembles a "copy run tftp" statement with the routers hostname embedded and saves the running config to a server.  Every time I manually run the TCL scipt, it runs like a charm.  Next step for me is to get the router to run this script once per day, so I set up a CEEM config to run this in the morning at 6am.   --  now  that part works, the "savenetconfig" event fires off at 6am.  The proof I have that it works is I can see the syslog message in the router log everytime the cronjob automatically runs.  I see no evidence of the this being executed --> " action 2 cli command "tclsh exp"


What am I doing wrong?

Router config contains:

event manager applet savenetconfig
 event timer cron cron-entry "0 6 * * *"
 action 1 cli command "enable"
 action 2 cli command "tclsh exp"
 action 3 syslog msg "CONFIG was written to MSPROD20 for AVPN config processing!"
 
TCL SCRIPT known as "exp" in flash:

set SAVECONF [open SAVECONF w]
set ending ".cfg"
set mycmd "copy running-config tftp://144.160.20.71/"
set runconfig [exec “show running-config”]
set foundposition [string first “hostname ” $runconfig]
set cutoff [string length “hostname ”]
if {$foundposition > -1} {
   set cutoff [string length “hostname ”]
   set begin [expr $foundposition + $cutoff]
   set end [string first “\n” $runconfig $begin]
   set end [expr $end - 2]
   set host [string range $runconfig $begin $end]
   puts $host
}
puts -nonewline $SAVECONF $mycmd
puts -nonewline $SAVECONF $host
puts -nonewline $SAVECONF $ending
close $SAVECONF
set mynewcmd [exec “more SAVECONF”]
puts $mynewcmd
exec $mynewcmd

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

You shouldn't be running tclsh out of EEM.  It burns resources, and it doesn't provide the richer debugging and access control that EEM Tcl will provide.  It doesn't even look like you need Tcl for this at all.  You could do:

event manager applet savenetconfig
 event timer cron cron-entry "0 6 * * *"
 action 1.0 cli command "enable"
 action 2.0 info type routername
 action 3.0 cli command "copy running-config tftp://144.160.20.71/$_info_routername.cfg"

This assumes you've configured file prompt quiet, though.

Hello Joseph,

Thanks HUGELY for your response.  I very much like your approach better than mine. I had no idea it could be simplified to just a few statements.   Although its extremely close, it isn't exactly working.  I thought originally I might have had some permissions issues but as I dig deeper, I dont really believe that to be the case..  I need to tell you also that my routers have aaa and that was responseable for part of my issue.  I think I also fixed that as well.  This is what I have been puting into a sample router along with debug/log:

no event manager applet savenetconfig
event manager session cli username cw2000
event manager applet savenetconfig
 event timer cron cron-entry "55 10 * * *"
 action 1.0 cli command "enable"
 action 2.0 info type routername
 action 3.0 cli command "copy running-config tftp://144.160.20.71/$_info_routername.cfg"

Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : CTL : cli_open called.
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : CC
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT :
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : ********************************************
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : * CONFIDENTIAL AND PROPRIETARY INFORMATION *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : *                                          *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : *    Solely for use by employees of AT&T.  *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : *     Not to be disclosed to or used by    *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : *       any person without the prior       *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : *        written permission of AT&T.       *
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : ********************************************
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT :
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT :
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : VIDEO-DEMO>
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : IN  : VIDEO-DEMO>enable
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : OUT : VIDEO-DEMO#
Jun 25 10:55:00: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : IN  : VIDEO-DEMO#copy running-config tftp://144.160.20.71/VIDEO-DEMO.cfg
Jun 25 10:55:20: %HA_EM-6-LOG: savenetconfig : DEBUG(cli_lib) : : CTL : cli_close called.

 

From the log, it looks PERFECT.  The actual file called VIDEO-DEMO.cfg is present on the server with EVERYONE in the permissions. But the above EEM script is NOT pushing the running-conf to this file. The interesting thing is, if I manually do a "copy running-config tftp://144.160.20.71/VIDEO-DEMO.cfg" at the router prompt, the file gets updated correctly with the latest running-config.  - I do have to answer questions though after the command is entered..  I guess that is my question with EEM, how would these questions get answered?  Even though I specify EVERYTHING in the command, the router still is asking me if 144.160.20.71 is the destination IP and VIDEO-DEMO.cfg is the filename.  -Debugging but not sure whats wrong yet..

 

 

This is why I said you'd need to have "file prompt quiet" configured.  That will make the command non-interactive.  You can make the applet interact with the prompts, but in this case, file prompt quiet is easier.

Joseph,  You are the man!   working extremely well now and I cant thank you enough!