Need some help.
I have a tcl script getting a variable containing an encrypted
password eg {xor}PG8adGh+NzA=
in the script below the encrypted password is assigned to set
propertyValue [lindex $argvX 3]
however, when the prop_attr variable is set containing $propertyValue
it fails becuase "{ }" are special characters. same applies when
$AdminConfig modify $jvm [list $prop_attr] is executed
I cannot for the life of my figure out have to tell tcl to totally
ignore the curly braces in a variable. Perhaps it can't be done - I
don't know.
I've tried \{ , [list $arg] etc.
If some one can suggest something - I will love you forever!
#--------------------------------------------------------------
# set up globals
#--------------------------------------------------------------
global AdminConfig
global AdminControl
global AdminApp
#--------------------------------------------------------------
# Main
#--------------------------------------------------------------
regsub -all {\\} $argv {/} argvX
set clusterName [lindex $argvX 0]
set serverInstanceNumber [lindex $argvX 1]
set propertyName [lindex $argvX 2]
set propertyValue [lindex $argvX 3]
set propertyDescription [lindex $argvX 4]
set nodeName [lindex $argvX 5]
set wasnode [string toupper $nodeName]
set serverName ""
append serverName $clusterName $wasnode "S0" $serverInstanceNumber
set prop_attr [list systemProperties [list [list [list name
$propertyName] [list value $propertyValue] [list description
$propertyDescription]]]]
#---------------------------------------------------------
# Get a list of cells
#---------------------------------------------------------
set cells [$AdminConfig list Cell]
foreach cell $cells {
#---------------------------------------------------------
# Get a list of clusters in this cell
#---------------------------------------------------------
set nodes [$AdminConfig list Node $cell]
foreach node $nodes {
set servers [$AdminConfig list Server $node]
#---------------------------------------------------------
# Get a list of member servers in this cluster
#---------------------------------------------------------
foreach server $servers {
set servername [$AdminConfig show $server name]
regsub -all {\{name} $servername {} servername1
regsub -all {\}} $servername1 {} servername2
set servername [string trim $servername2]
if {$servername=="$serverName"} {
set jvm [$AdminConfig list JavaVirtualMachine $server]
$AdminConfig modify $jvm [list $prop_attr]
}
}
}
}
$AdminConfig save
the argv is a string that is separated by spaces. lindex works with
this as it were a list in most cases but not in yours.
In a real list it works fine
% set tcl_patchLevel
8.4.14
% set a "{xor}PG8adGh+NzA="
% set x [list hallo welt $a]
% lindex $x 2
{xor}PG8adGh+NzA=
In a string it doesn't
% set x "hallo welt $a"
% lindex $x 2
list element in braces followed by "PG8adGh+NzA=" instead of space
Solution:
Make your argvX a list:
% set y [split $x " "]
hallo welt {{xor}PG8adGh+NzA=}
% lindex $y 2
{xor}PG8adGh+NzA=
Is there a way to take your program and trim off non-relevant pieces
until you have the smallest coherent example of your problem?
Here's why I ask:
$ /usr/tcl84/bin/tclsh
% info patchlevel
8.4.7
$ cat ~/argv.tcl
#! /usr/tcl84/bin/tclsh
set name [lindex $argv 0]
puts $name
$ ~/argv.tcl "{abc}xyz" 123
{abc}xyz
As you can see - the braces don't cause a problem with set or being in
the argv variable. No need to do anything with regexp, etc.
My suggestion is the following.
Take a deep breath, go back to where you were before you started
trying to fix the handling of the { in the value, make a copy of the
program. In the copy, remove all the code after the point where you
are finding the error, as it isn't relevant. Modify the remaining code
so it runs. Then, delete any statement which is unrelated to the
specific assignment giving you grief. Keep testing the fragment as it
gets smaller and smaller. As long as it keeps raising an error, keep
seeing what if anything can be removed.
Eventually, you should be down to a small number of lines that still
exhibit the problem. Make certain that any site specific things -
executables, etc. - are changed to more generic invocations. That way,
anyone should be able to run the code and see the problem.
Let us see that and we should be able to help.
P.S. If the code stops "breaking" during the above process, then the
code you just removed is critical to the situation, so backing out the
changes and focusing on that code is the next step.
Correction. argv is a list. Big difference.
FWIW, tcl has absolutely not problem whatsoever storing special
characters in variables. We'll hopefully get to why you're having
trouble below.
> I cannot for the life of my figure out have to tell tcl to totally
> ignore the curly braces in a variable. Perhaps it can't be done - I
> don't know.
>
> I've tried \{ , [list $arg] etc.
>
> If some one can suggest something - I will love you forever!
>
>
> #--------------------------------------------------------------
> # set up globals
> #--------------------------------------------------------------
> global AdminConfig
> global AdminControl
> global AdminApp
>
> #--------------------------------------------------------------
> # Main
> #--------------------------------------------------------------
> regsub -all {\\} $argv {/} argvX
I think your problem starts with that last line. You are taking a valid
list -- $argv -- and converting it to a string (implicitly), and also
converting backslashes to a forward slash. Later, when you are using
lindex, the interpreter first must convert that new string back to a
list, most likely with results you don't expect.
Are you aware, for example, that Tcl may insert backslashes into the
string representation of a list to preserver the "listness" of the data?
If you then remove those backslashes you potentially corrupt the list,
depending on the contents.
Instead, you should be doing that transformation on an
element-by-element basis, for example:
set argvX [list]
foreach element $argv {
regsub -all {\\} $element {/} new
lappend argvX $new
}
If that doesn't help, please show us the exact error you are getting,
and what line of code is throwing that error. And perhaps explain why
you are converting backslashes to forward slashes -- perhaps that can be
avoided or done in a different way.
Thanks!
I've tried what you've suggested, but the line of code for
$AdminConfig just doesn't work.
I stripped the argument where the Variable is set (set propertyValue
[lindex $argvX 3]) to PG8adGh+NzA= instead of {xor}PG8adGh+NzA=
Then I added set property "{xor}$propertyValue"
then set str [split $property " "]
however, The code for $AdminConfig modify...(see below) fails. The
error is:
[wsadmin] WASX7017E: Exception received while running file "../JACL/
JVMProperties.jacl"; exception information:
java.lang.IllegalArgumentException:
java.lang.IllegalArgumentException: WASX7122E: Expected "}" not
found.
[wsadmin] {systemProperties {{{name AppLDAPBindPwdd} {value lindex
{{{xor}PG8adGh+NzA=}} 0} {description {LDAP Bind UserID Password}}}}}
[wsadmin]
#---------------------------------------------------------
# Get a list of cells
#---------------------------------------------------------
set cells [$AdminConfig list Cell]
foreach cell $cells {
#---------------------------------------------------------
# Get a list of clusters in this cell
#---------------------------------------------------------
set nodes [$AdminConfig list Node $cell]
foreach node $nodes {
set servers [$AdminConfig list Server $node]
#---------------------------------------------------------
# Get a list of member servers in this cluster
#---------------------------------------------------------
foreach server $servers {
set servername [$AdminConfig show $server name]
regsub -all {\{name} $servername {} servername1
regsub -all {\}} $servername1 {} servername2
set servername [string trim $servername2]
if {$servername=="$serverName"} {
set jvm [$AdminConfig list JavaVirtualMachine $server]
$AdminConfig modify $jvm [list [list systemProperties [list [list
[list name $propertyName] [list value [lindex $str 0]] [list
description $propertyDescription]]]]]
}
}
}
}
Thanks in advance
> I've tried what you've suggested, but the line of code for
> $AdminConfig just doesn't work.
>
> I stripped the argument where the Variable is set (set propertyValue
> [lindex $argvX 3]) to PG8adGh+NzA= instead of {xor}PG8adGh+NzA=
>
> Then I added set property "{xor}$propertyValue"
> then set str [split $property " "]
What exactly are you trying to accomplish? If $propertyValue has stored
in it {xor}PG8adGh+NzA=, there's no need to strip the {xor} only to add
it later.
Are you aware that the [split $property " "] will convert the string to
a list? You will no longer have a string.
I suspect your problems arise in part because you try to treat lists
like strings in your code.
>
> however, The code for $AdminConfig modify...(see below) fails. The
> error is:
>
> [wsadmin] WASX7017E: Exception received while running file "../JACL/
> JVMProperties.jacl"; exception information:
> java.lang.IllegalArgumentException:
> java.lang.IllegalArgumentException: WASX7122E: Expected "}" not
> found.
> [wsadmin] {systemProperties {{{name AppLDAPBindPwdd} {value lindex
> {{{xor}PG8adGh+NzA=}} 0} {description {LDAP Bind UserID Password}}}}}
> [wsadmin]
Ah, so Tcl isn't failing, the thing you are calling is failing because
you are giving it something it doesn't expect.
Maybe the easiest way to solve this problem is for you to show us a
command line that works when values are hard-coded. From that we can
figure out how to create a complete command line that works.
By the way...something looks fishy in the error report. Is it normal to
expect the literal string "lindex" to appear in the data stream? Notice
how you have {value lindex {{{xor}PG8adGh+NzA=}} 0}, which looks quite
suspicious. I would have expected something like {value {xor}PG8adGh+NzA=}
Are you sure you're not forgetting to enclose a "lindex {...} 0" inside
square brackets somewhere? It almost looks like you are doing this:
set foo [list [list name $name] [list value lindex $value 0]
... when you should be doing
set foo [list [list name $name] [list value [lindex $value 0]]
I don't see that faux pas in the code you posted, but it's often the
case that people post code that doesn't generate the error they post.
Hi - thanks for replying
Yes - I noticed the same thing with the curly brackets - the error
shows more clurly brackets than what there should be. :S
The following code is what is failing:
$AdminConfig modify $jvm [list [list systemProperties [list [list
[list name $propertyName] [list value [lindex $str 0]] [list
description $propertyDescription]]]]]
Thanks!
That appears to be a perfectly well-formed Tcl command, if we can assume
stat str is a list. But while it's a well-formed Tcl command, it's
probably not a well-formed list of arguments to $AdminConfig which has
it's own unique syntax. It might help if you could somehow provide us a
link to a man page for that command, or reproduce the usage statement.
So, your task is to now show us exactly what that command looks like
when everything is expanded. The simplest might be to pass the whole
thing to puts.
Next, show us what you *want* it to be by hand-typing a command that you
know works.
With those two pieces of information -- what you have and what you want
it to look like -- we can figure out what you're doing wrong. In fact,
with those two pieces of information you can probably figure it out
yourself. My guess is you simply have too many calls to [list], but
without knowing the exact format expected by $AdminConfig, that's only a
guess.
Thanks again.
The working version of the code is below.
$AdminConfig modify $jvm [list [list systemProperties [list [list
[list name $propertyName] [list value $propertyValue] [list
description $propertyDescription]]]]]