cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5635
Views
0
Helpful
32
Replies

Asynchronous TCL Scripting

mmoles001
Level 1
Level 1

I am trying to write some Asynchronous TCL code to make things more efficent.   This is just a simple example, but in reality it will SSH into a device, run a command, do some math, and write the output to the switch.

The whole "after" thing is throwing me off.  When i run it locally trough tclsh86 , i need to run the "update" command to follow up with the results.   How and what do i need to do to get this to work?

#***************************************CODE**********************************************************

::cisco::eem::event_register_timer watchdog time 15 maxrun 15

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

proc checkDevice { interface tempName aNumber waitTime} {

puts "  "

puts "$tempName - Start"

after $waitTime

puts "$tempName - After"

if [catch {cli_write $interface "event manager environment tempName $aNumber"} _cli_result] {

error $_cli_result $errorInfo

}

puts "$tempName - EXIT"

}

if [catch {cli_open} result] {

error $result $errorInfo

} else {

array set cli1 $result

}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {

error $_cli_result $errorInfo

}

after 0 checkDevice $cli1(fd) A 11 1000

after 0 checkDevice $cli1(fd) B 22 200

after 0 checkDevice $cli1(fd) C 33 4000

after 0 checkDevice $cli1(fd) D 44 1000

if [catch {cli_exec $cli1(fd) "exit"} _cli_result] {

error $_cli_result $errorInfo

}

catch {cli_close $cli1(fd) $cli1(tty_id)} result

32 Replies 32

Well i just realized i cannot run 2 tcl scripts at the same time.   That is disappointing.   I guess i will need to code this all in 1 script and hop trough 1 at a time.   

Well, i appreciate all the help.  I learned quite a bit from this endeavor.

You can run two scripts at the same time by increasing the script thread count using the command "event manager scheduler script thread class default number X" where X is the desired number of parallel scripts you want.  But note on the previous point, while you can schedule multiple things in the queue, they will run in series waiting for the previous one to yield or complete.  Using cli_write may work as you won't need to read for a prompt right away.

Thats good to know.     I think i will be sticking with 1 script and not do any weird queuing stuff.    The fidelity of my data will be a tad worse, but the switch will struggle with all of that going on at once.

Hopefully i can loop trough the X devices and send the status command, then once the loop is done, that i loop trough it again with the reads.   The reads will end up causing a wait, but it should only be the first one.   And if thats the case, then i could cycle trough these quick.    If not and i need to cli_exec each command , it will be fine.

I'll send you a PM with my results and a bit more context of the problem.  Not sure what the confidentiality rules are with my project, but posting data about it on the forum probaby isnt the best of ideas.  Once again, thanks for all the help.

Review Cisco Networking for a $25 gift card