cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
716
Views
0
Helpful
6
Replies

Use of gset in CSM TCL Script

lpassmore
Level 1
Level 1

Hello,

I am trying to write a TCL script on a CSM (Code Ver 4.1) that retains the value of a variable between probe instances (so I can increment and check a variable in each probe attempt). Looking at the documentation there is supposed to be a 'gset' command that does this but cannot make this work.

The example says 'gset var 1 ; incr var'.

I have several problems with this:

1. I would think that this would set the value of var to 1 each time it runs and then increment it (maybe)

2. How can I read the value of the persistent variable without it causing an error if it doesn't exist?

3. It doesn't seem to work anyway as var doesn't appear in the Persistent Variables section of 'show mod csm x tech script'

Any ideas on this or on where I can get some examples where the gset command is used?

Many Thanks

LP

6 Replies 6

Gilles Dufour
Cisco Employee
Cisco Employee

I think the gset means set the variable globally if it does not exist yet.

If it does exist, do nothing.

Here is how it was used for a script

gset pkid 1

incr pkid

if { $pkid >= 255 } {

set pkid 1

}

Hope this will help you make it work.

Gilles.

Thanks Giles, always very prompt with your replies.

What you have put in is exactly how I had interpreted how it should work given the info in the manual, and is how I tested it.

Here is an excerpt from my code (Note that I used 'counter' not 'pkid' but I hope that doesn't make any difference).

#!name = TESTMAIL_PROBE

########################################################################################

#

#-------------------------------------------

# main

#-------------------------------------------

# parse cmd line args and initialize variables

## set debug value

set debug 0

if { [ regsub -nocase "DEBUG" $argv "" argv] } {

set debug 1

}

csm_debug "initializing variable"

if { [ llength $argv ] != 3 } {

set EXIT_MSG "Error config : script TestMAIL_PROBE < mailSever|'none'> \[DEBUG\]"

puts $EXIT_MSG

exit 5001

}

gset counter 1

incr counter

puts "Counter: $counter"

set ip $csm_env(realIP)

...

Here are the results:

Mar 19 07:58:38.813: CSM4: Counter: 2

Mar 19 07:59:09.144: CSM4: Counter: 2

Mar 19 07:59:39.375: CSM4: Counter: 2

Mar 19 08:00:09.410: CSM4: Counter: 2

Mar 19 08:00:39.378: CSM4: Counter: 2

Mar 19 08:01:09.609: CSM4: Counter: 2

Mar 19 08:01:39.708: CSM4: Counter: 2

show mod csm 4 tech script results (edited)

:

==========================================================================

SCRIPT(0xbdf7840) stat blk(0xbdf78a8): TCL_TESTMAIL_PROBEbdf7840

CMDLINE ARGUMENT:

curr_id 1 argc 3 flag 0x0:: http://fail x.x.3.100 blah@blah.com

type = PROBE

task_id = 0x0: run_id = 729 ref count = 2

task_status = TASK_DONE run status = OK

start time = SUN MAR 18 23:06:13 2007

end time = SUN MAR 18 23:06:13 2007

runs = 36 +-30735

resets = 36 +-30735

notrel = 0 +0

buf read err = 0 +-9

killed = 0 +-115

panicd = 0 +0

last exit status= 5001 last Bad status = 5001

Exit status history:

**TCL Controller:

------------------------

tcl cntrl flag = 0x7fffffff

#select(0) close_n_exit(0) num_sock(1)

MEM TRACK last alloc(0) last size(0) alloc(0) size(0)

hm_ver (106) flag(0x0) script buf(0xbe54ff0) new script buf(0x0)

lock owner(0x0) sig taskdel:0 del:0 syscall:0 syslock:0 sig_select

script ptr (0xbe8a2d0) id(1)

Config(0xbe89fb8) probe -> x.x.230.5:0

tclGlob(0xbe88bf0)

SCRIPT RESOURCE(0xbe53aa0)-------

#Selects(0) Close_n_exit(0) #Socket (1)

OPEN SOCKETS:

Persistent Variables

--------------------

Last erroInfo =

Last errorCode =

Last panicInfo =

EXIT_MSG = TESTMAIL_PROBE:x.x.230.5:80: probe fail : status code is 500

I expect the probe to fail (by design at this stage for testing), but I also would expect that there be a Persistent Variable (called counter) and it is not there.

Any clues? I expect that I have missed something small but significant. Is there one silly line that I need to put in that maybe I have missed?

Thanks again

LP

it works for me:

I just added the gset and incr commands to the echo probe and it I do see the counter increasing.

gset counter 1

# parse cmd line args and initialize variables

puts "initializing variable 2"

set EXIT_MSG "Error config: script ECHO_PROBE "

incr counter

puts "Counter: $counter"

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.48:21: opening socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.48:21: receiving response

ECHO_PROBE_SCRIPT:192.168.30.48:21: closing socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: probe failed : expect 'csm_test' but got '220 Welcome to Linux1 FTP service.'

initializing variable 2

Counter: 7

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.24:7: opening socket

ECHO_PROBE_SCRIPT:192.168.30.24:7: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.24:7: receiving response

ECHO_PROBE_SCRIPT:192.168.30.24:7: closing socket

ECHO_PROBE_SCRIPT:192.168.30.24:7: probe success

initializing variable 2

Counter: 7

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.24:21: opening socket

ECHO_PROBE_SCRIPT:192.168.30.24:21: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.24:21: receiving response

ECHO_PROBE_SCRIPT:192.168.30.24:21: closing socket

ECHO_PROBE_SCRIPT:192.168.30.24:21: probe failed : expect 'csm_test' but got '220 Welcome to Linux1 FTP service.'

initializing variable 2

Counter: 8

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.48:7: opening socket

ECHO_PROBE_SCRIPT:192.168.30.48:7: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.48:7: receiving response

ECHO_PROBE_SCRIPT:192.168.30.48:7: closing socket

ECHO_PROBE_SCRIPT:192.168.30.48:7: probe success

initializing variable 2

Counter: 8

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.48:21: opening socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.48:21: receiving response

ECHO_PROBE_SCRIPT:192.168.30.48:21: closing socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: probe failed : expect 'csm_test' but got '220 Welcome to Linux1 FTP service.'

initializing variable 2

Counter: 8

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.24:7: opening socket

ECHO_PROBE_SCRIPT:192.168.30.24:7: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.24:7: receiving response

ECHO_PROBE_SCRIPT:192.168.30.24:7: closing socket

ECHO_PROBE_SCRIPT:192.168.30.24:7: probe success

initializing variable 2

Counter: 8

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.24:21: opening socket

ECHO_PROBE_SCRIPT:192.168.30.24:21: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.24:21: receiving response

ECHO_PROBE_SCRIPT:192.168.30.24:21: closing socket

ECHO_PROBE_SCRIPT:192.168.30.24:21: probe failed : expect 'csm_test' but got '220 Welcome to Linux1 FTP service.'

initializing variable 2

Counter: 9

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.48:7: opening socket

ECHO_PROBE_SCRIPT:192.168.30.48:7: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.48:7: receiving response

ECHO_PROBE_SCRIPT:192.168.30.48:7: closing socket

ECHO_PROBE_SCRIPT:192.168.30.48:7: probe success

initializing variable 2

Counter: 9

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.48:21: opening socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: sending resquest string

ECHO_PROBE_SCRIPT:192.168.30.48:21: receiving response

ECHO_PROBE_SCRIPT:192.168.30.48:21: closing socket

ECHO_PROBE_SCRIPT:192.168.30.48:21: probe failed : expect 'csm_test' but got '220 Welcome to Linux1 FTP service.'

initializing variable 2

Counter: 9

Script start

this is a csm echo request

ECHO_PROBE_SCRIPT:192.168.30.24:7: opening socket

Hmmm. Ya gotta love modern technology!

Thanks for that. I tried it in that script & it works too. Now for why it won't work in the mail script.

LEave it to me. Thanks for your help

Apologies for hijacking this thread.

Did you manage to work out why the gset was not working in your mail script? I've got exactly the same issue.

gset not working - solved!

A little bit of trial and error provided the solution. The variables are only saved when they are present in the scope that the script exits.

This means that if you exit from a "proc", then you must declare the variable that you want exported as a global in the proc.

If you take the following simple example, only MyCounterOne is persistent:

gset MyCounterOne 1

gset MyCounterTwo 2

proc DoMyExit {} {

global MyCounterOne

exit 5000

}

DoMyExit