Question

I need to capture the output of the below to a variable. I know we can get to serverRuntime or domainRuntime() trees and get the state. But need to get the below working.

wls:/owb/serverConfig> state('Server1')
Current state of 'Server1' : RUNNING

I tried two ways:

wls:/owb/serverConfig> print state('Server1')
Current state of 'Server1' : RUNNING
None

wls:/owb/serverConfig> x=state('Server1')
Current state of 'Server1' : RUNNING

wls:/owb/serverConfig> print x
None
Was it helpful?

Solution

You have to use the getState() method of server runtime mbean. You can obtain the server runtime mbean by navigating into wlst runtime tree or by using a lookup method.

Sample:

domainRuntime()
slrBean = cmo.lookupServerLifeCycleRuntime('Server1')
status = slrBean.getState()
print 'Status of Managed Server is '+status

See also Getting Runtime Information in WLST official documentation.

OTHER TIPS

This same question was raised by Dianyuan Wang with me 2011. Here is the steps to resolve your issue. 1. Capture the output of state command using redirect, stopRedirect command 2. Use the Python regular expression in search function to extract the desired server output.

Code snippet is here

            fileName='/tmp/myserver_state.txt'
            redirect(fileName)
            state(server_nm,'Server')
            stopRedirect()
            f = open(fileName)
            try:
                    for line in f.readlines():
                            if re.search('Current state',line):
                                    status[server_nm]=line
            except:
                    continue

Now you can apply desired logic after this block.

Cheers!! HTH

Here is what I am using and is working like charm

    cd("/ServerRuntimes/ms1")
    state=cmo.getState()
    print state
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top