linuxshelljythonwsadmin

Pass a variable from Jython (wsadmin) to shell script


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

The caller shell script (getValue.sh) would 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) would have:

cellName = AdminControl.getCell()
return cellName

How can I store the value of cellName into a variable in my shell script, for example, CELL_NAME, that I could use like:

echo "Cell Name is: " ${CELL_NAME}

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

If I am using a lot of functions in the Jython script, is there a way to pass one of the values to my shell script? i.e.

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

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

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

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

I there a way to store multiple values into different shell script variables? i.e.

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

... This way I could run one Jython script that would retrieve multiple values and use those multiple values in my shell script for further processing.


Solution

  • Matt put me on the right track. I was able to accomplish what I needed by adding " | tail -1" to the command. You probably already know how a wsadmin SOAP connection always spits out the 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 take only the last part of the screen output to assign to my variable, thus using "tail -1".

    The command becomes:

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

    Using that, you have to be careful about what you are printing on the screen in the Jython script, because only the last print will be assigned to the variable. You can adjust what you need with the tail command.