cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1723
Views
10
Helpful
1
Replies

TCL: Best way to store Variables between TCL script run times?

tproeber
Level 1
Level 1

If I am simply running a TCL script every 10 seconds, how can I store varilable info between the TCL script runnings? 

I have tried:

+ Writing the info to an EEM Variable in the Sho-Run, and then reading in this info each time the script runs, and then writing the changes to the EEM Variable before exiting

    -- this works, but the available storage space is short and makes the sho-run looks "bad" for non=TCL types

+  Writing and reading the variable info to Flash: files.

   --  this works too, but a Flash has only so many writes and then when that limit is reached . . .it boots in RMON

Q: Can I do this?

Disclaimer:  I am not a REAL programmer, but a scripter . . .

Thanks,

Tim

CCNP - Security

CCNP - Wireless

1 Reply 1

Joe Clarke
Cisco Employee
Cisco Employee

If you're using EEM, you can use a system called contexts to save data in memory between executions.  Here is some example code:

# Retrieve any previous context data

if { [catch {context_retrieve MYCTXT myvar} result] } {

    set myvar 0

} else {

    set myvar $result

}

...

# Save the variable for the next run

catch {context_save MYCTXT myvar}

You can even save arrays like this:

if { [catch {context_retrieve MYCTXT myarr} result] } {

    array set myarr [list]

} else {

    array set myarr $result

}

....

catch {context_save MYCTXT myarr}

Review Cisco Networking for a $25 gift card