2

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
PavanDevarakonda
  • 625
  • 5
  • 27
SSA
  • 73
  • 1
  • 9

3 Answers3

3

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.

Mariano Paniga
  • 626
  • 12
  • 26
  • I tried it and I get the below error: wls:/owb/domainRuntime> slrBean = cmo.lookupServerLifecycleRuntime('owb001') Traceback (innermost last): File "", line 1, in ? AttributeError: lookupServerLifecycleRuntime – SSA Apr 27 '14 at 05:59
  • 3
    This is the correct answer but the there should be CAPS C for Cycle – SSA Apr 28 '14 at 20:02
  • Fixed code with CAPS C in lookupServerLifeCycleRuntime , many thanks @user3460652 – Mariano Paniga Apr 30 '14 at 08:30
1

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

PavanDevarakonda
  • 625
  • 5
  • 27
  • Yes, I think this is the only way to do it, there isnt any other way without writing to a file? – SSA Apr 28 '14 at 09:05
0

Here is what I am using and is working like charm

    cd("/ServerRuntimes/ms1")
    state=cmo.getState()
    print state