cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
14440
Views
4
Helpful
17
Replies

Execute TCL Script On Router Startup

KyleArnold
Level 1
Level 1

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?

3 Accepted Solutions

Accepted Solutions

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.

View solution in original post

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"

View solution in original post

KyleArnold
Level 1
Level 1

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.

View solution in original post

17 Replies 17

Joe Clarke
Cisco Employee
Cisco Employee

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

Hi Joseph,

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

The version IOS is 15.1(2)

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.

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

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.

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

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
Level 1
Level 1

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

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.

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
Level 1
Level 1

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

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.

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"
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: