webspherewsadminjacl

wsadmin.sh reading multiline commands from stdin


Piped wsadmin can't run scripts with flow control, because in that mode a newline separates commands.

Simple example from http://www-01.ibm.com/support/knowledgecenter/SSEQTP_7.0.0/com.ibm.websphere.base.iseries.doc/info/iseries/ae/cxml_jacl.html?lang=en :

set numbers {1 3 5 7 11 13}
foreach num $numbers {
    puts $num
}

output:

[wasuser@oktest-prod-app-2 ~]$ ${WC_WSADMIN:?} -f test.jacl
WASX7209I: Connected to process "dmgr" on node EmProdDmgrNode using SOAP connector;  The type of process is: DeploymentManager
1
3
5
7
11
13
[wasuser@oktest-prod-app-2 ~]$ ${WC_WSADMIN:?} <test.jacl
WASX7209I: Connected to process "dmgr" on node EmProdDmgrNode using SOAP connector;  The type of process is: DeploymentManager
WASX7029I: For help, enter: "$Help help"
wsadmin>1 3 5 7 11 13
wsadmin>WASX7015E: Exception running command: "foreach num $numbers {"; exception information:
 com.ibm.bsf.BSFException: error while eval'ing Jacl expression:

wsadmin>WASX7015E: Exception running command: "puts $num"; exception information:
 com.ibm.bsf.BSFException: error while eval'ing Jacl expression:
can't read "num": no such variable
    while executing
"puts $num"
wsadmin>WASX7015E: Exception running command: "}"; exception information:
 com.ibm.bsf.BSFException: error while eval'ing Jacl expression:
invalid command name "}"
    while executing
"}"

My script is generated. Beside storing it in a temporary file is there a workaround? I know it's possible to do this:

foreach num $numbers { puts $num }

but what if there must be more than one command in the block?


Solution

  • Use a semicolon:

    foreach num $numbers { puts $num; puts $num }
    

    But you're probably better off writing the script to a temporary file.