Linux – Pass variables from Jython (wsadmin) to shell scripts

Pass variables from Jython (wsadmin) to shell scripts… here is a solution to the problem.

Pass variables from Jython (wsadmin) to shell scripts

I’m trying to pass the value retrieved from WebSphere to a variable in my caller’s shell script using a Jython script called by wsadmin.sh.

The caller shell script (getValue.sh) will have:

#!/bin/sh

/opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang jython -conntype SOAP -f /home/user/Jython.py

exit 0

The Jython script (Jython.py) will have:

cellName = AdminControl.getCell()
return cellName

How to store the value of cellName into a variable in my shell script, e.g. CELL_NAME, I can use it like this:

echo "Cell Name is: " ${CELL_NAME}

This version of the Jython script is a lot simpler than the one I use in reality, but I think the concept is the same.

If I use a lot of functions in my Jython script, is there a way to pass one of the values to my shell script? Namely

def getValue1():
     value1 = "1"
     return value1

def getValue2():
     value2 = "2"
     return value2

def getValue3():
     value3 = "3"
     return value3

print getValue1()
print getValue2()
print getValue3()

Is there a way for me to store multiple values into different shell script variables? Namely

echo "Value #1: " ${VALUE_ONE}
echo "Value #2: " ${VALUE_TWO}
echo "Value #3: " ${VALUE_THREE}

… This allows me to run a Jython script to retrieve multiple values and use those multiple values for further processing in my shell script.

Thank you for any help.

Solution

Thanks Matt. You put me on the right track. By adding “| tail -1” to the command, I was able to do what I wanted. You may already know how wsadmin SOAP connections always output the following line:

WASX7209I: Connected to process "dmgr" on node labCellManager01 using SOAP connector;  The type of process is: DeploymentManager

… So I had to find a way to assign only the last part of the screen output to my variable, hence the use of “tail -1”.

The command becomes:

result=`/opt/ibm/WebSphere/AppServerV70/bin/wsadmin.sh -lang jython -conntype SOAP -f /home/user/Jython.py | tail -1`

When using it, you must pay attention to what is printed on the screen in the Jython script, because only the last print will be assigned to the variable. You can use the tail command to adjust what you need.

Thank you for your help

Related Problems and Solutions