Execute TCL Script On Router Startup

Answered Question
May 2nd, 2013
User Badges:

I am using one of the latest 5000 series embedded routers and trying to get my TCL script to execute on Router startup, with little success.

It's the first time for me, tho i've been through the relevent Cisco documents,  the official book on TCL scripting as well as many examples found online.

Obviously I am missing something somewhere and it has me stumped. I thought it would be a simple task.


Can anyone provide a step by step instruction/requirements to get a TCL script to execute on a Cisco router everytime it boots?

Correct Answer by Joe Clarke about 3 years 11 months ago

Right there with what Mike said, but give this Tcl policy a try instead:


::cisco::eem::event_register_timer cron cron_entry @reboot
puts "Test complete"
Correct Answer by mtimm about 3 years 11 months ago

Hi Kyle,


With the adventerprisek9 image, you should not need to run this through an applet.  You should be able to run it directly from a Tcl policy.


event manager directory user policy flash:

event manager policy test.tcl authorization bypass


Mike


Edit:  By the way, when you use puts, the output should go to the syslog.  There have been bugs though where the output may go to various locations or get "stuck."  So please check the output of 'show log' and see if the output has gone there.

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
Joe Clarke Fri, 05/03/2013 - 16:39
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

I'm not sure what a 5000 series is specifically.  Exactly what model are you using and what version of code is it running?

KyleArnold Tue, 05/07/2013 - 19:45
User Badges:

Hi Joseph,


Specifically, it's a Cisco 5940 embedded router. Very nice to it is.

The version IOS is 15.1(2)

Joe Clarke Tue, 05/07/2013 - 22:34
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Then the document referenced in this thread should work.  I personally recommend the cron solution with @reboot.  If that doesn't work, then you should post your EEM policy.

mtimm Tue, 05/07/2013 - 23:00
User Badges:
  • Cisco Employee,

Hi Joe,


It looks like the adventerprisek9 featureset has the EEM Tcl subsystem but the entbase featureset does not on this platform.  At least in the 15.1(2)GC* code that seems to be the case.


So in order for this to work with a Tcl script in EEM on this platform, one would need to use the adventerprisek9 featureset.  It is really confusing because the entbase featureset includes Tcl, but not EEM Tcl.


Mike

Joe Clarke Tue, 05/07/2013 - 23:03
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Interesting.  Thanks, Mike.  Not sure if that applies, or what the actual symptoms of the problem are, but it's a good data point to know.

mtimm Wed, 05/08/2013 - 01:50
User Badges:
  • Cisco Employee,

Hi Joe,


I think it does apply.  Sorry I wasn't clear.  All the other EEM subsystems appear to be included in the entbase featureset for this platform except the EEM Tcl subsystem.  So what Jeffrey is suggesting is writing the script in pure Tcl then triggering it with an EEM applet because EEM Tcl doesn't exist in that feature set.  That sort of a workaround would only be needed because for some reason the platform excludes the EEM Tcl subsystem from the entbase feature set.


To use pure EEM Tcl, on this platform one would need to go to the adventerprisek9 feature set.


Mike

Joe Clarke Wed, 05/08/2013 - 05:39
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Right.  I meant I wasn't sure it applied because I haven't seen a show ver yet.  All I know is the router is running 15.1(2) code.  Certainly if this is entbase, then you're absolutely right.

Jeffrey Simon Tue, 05/07/2013 - 03:28
User Badges:

I was attempting to do something similar.  I would suggest trying to rewrite your script in TCL.  I would say that EEM is better supported than TCL.  But even if you do not rewrite the script, you can call it using EEM.  Cisco advises against this though.


This would be an entire config.  I have some extras built in to my scripts like "event manager session cli username USER", "authorization bypass" and "maxrun"


event manager session cli username "USER"

event manager applet APPLET_NAME authorization bypass

event syslog pattern "event syslog pattern "SYS-5-RESTART" maxrun 120

action 1.0 cli command enable

action 2.0 cli command tclsh SCRIPT.TCL


This would execute a TCL at boot time, but you may experience some authorization type problems.  If you do, post the results you are getting. 


This should work, but again, consider recoding it to EEM.  If you want to post a copy of your script I will attempt to help you walk through it.


Jeff

KyleArnold Tue, 05/07/2013 - 19:53
User Badges:

Hi Jeffrey,


Thanks for the info.

It looks very similar to what I have done, but will try yours exactly and report back.

One thing I wasn't sure of was, if there was required code in my TCL script to assist auto start on power up.

Registering of the TCL scrip requirements, i'm not too sure of as well.


Kyle.

Jeffrey Simon Tue, 05/07/2013 - 19:58
User Badges:

I had a ton of problems running the TCL scripts from EM, which is really the only way you can do it unless you run tclsh script_name.tcl from privileged exec mode. 


If you register the script it is quite a lot of work.  I would stay away from that route unless absolutely possible...


Would you be comfortable posting the script and maybe I can help you relogic the script for EEM?  If not, let me know what the script is doing and I will see if I can offer some more specific feedback.


Hope this helps.


Jeff

KyleArnold Wed, 05/08/2013 - 20:30
User Badges:

Thanks guys for the assistance. I'm now starting to understand what is happening.

The script I am developing is 'restricted' but as a test i'm trying to get a simple script to autorun.


# test.tcl


::cisco::eem::event_register_syslog pattern "SYS-5-RESTART"
puts "Test complete"


and the EEM:

event manager applet start-up authorization bypass

event syslog pattern "SYS-5-RESTART" maxrun 120

action 1.0 cli command "enable"

action 2.0 cli command "tclsh flash:test.tcl"


and the IOS image = c5940-adventerprisek9-mz.SPA.151-2.GC.bin
TCL version = 8.3.4


The above doesn't work for me.
No errors are reported, I just simply don't see the output appear.
Even tho the script runs perfectly otherwise when 'called' from the (tclsh)# prompt.

Think I need to do a bit more research.
The boss is getting a little anxious now tho. lol
Correct Answer
mtimm Wed, 05/08/2013 - 22:31
User Badges:
  • Cisco Employee,

Hi Kyle,


With the adventerprisek9 image, you should not need to run this through an applet.  You should be able to run it directly from a Tcl policy.


event manager directory user policy flash:

event manager policy test.tcl authorization bypass


Mike


Edit:  By the way, when you use puts, the output should go to the syslog.  There have been bugs though where the output may go to various locations or get "stuck."  So please check the output of 'show log' and see if the output has gone there.

Correct Answer
Joe Clarke Wed, 05/08/2013 - 22:53
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

Right there with what Mike said, but give this Tcl policy a try instead:


::cisco::eem::event_register_timer cron cron_entry @reboot
puts "Test complete"
KyleArnold Wed, 05/08/2013 - 23:49
User Badges:

Success!!!


Thank you all so very much.

The winning combination is as below.


TCL script test.tcl placed in Flash memory.


# test.tcl

::cisco::eem::event_register_timer cron cron_entry @reboot
puts "Test complete"


and EEM


event manager directory user policy flash:

event manager policy test.tcl authorization bypass



After the IOS booted up, this appeared ... %HA_EM-6-LOG: test.tcl: Test complete


This is awesome and am very appreciative of the time you guys have given to help.

And the boss now has a smile on his face, priceless.


Cheers,

Kyle.

Jeffrey Simon Thu, 05/09/2013 - 03:01
User Badges:

Just to add one more point to this.

You should be aware that there are authorization problems with EM activated TCL and TACACS.

When I coded my TCL script I had to work around this. But prior to working around this I discovered that "authorization bypass" does not apply to TCL.

I had to create a TACAS account and local user account from the script.

Jeff

Sent from Cisco Technical Support iPhone App

KyleArnold Thu, 05/09/2013 - 18:52
User Badges:

Yes, I can see what your saying.

I may need to address this with the current .tcl app I am developing.


Thanks Jeffrey.

Actions

This Discussion

Related Content