Querying server state using scripting
You can use the wsadmin tool and scripting to query server states. Before starting this task, the wsadmin tool must be running. See the Start the wsadmin scripting client article for more information.
Overview
When querying the server state, the following command steps return a value of STARTED if the server is started. If the server is stopped, the command does not return a value.
In a ND environment, you also can query for the server status from the deployment manager. If the server is active, the command returns the STARTED return value. If the server is stopped, the command returns the STOPPED return value.Perform the following steps to query the server state:
Procedure
- Identify the server and assign it to the server variable. The following example returns the server MBean that matches the partial object name string:
- Use Jacl:
set server [$AdminControl completeObjectName cell=mycell,node=mynode, name=server1,type=Server,*]
- Use Jython:
server = AdminControl.completeObjectName('cell=mycell,node=mynode, name=server1,type=Server,*') print serverExample output:
WebSphere:cell=mycell,name=server1,mbeanIdentifier=server.xml#Server_1, type=Server,node=mynode,process=server1,processType=ManagedProcessIf the server is stopped, the completeObjectName command returns an empty string ( ' ' ).
- Query for the state attribute. In addition to using the previous step, you can also query for the server state attribute. For example:
- Use Jacl:
$AdminControl getAttribute $server state
- Use Jython:
print AdminControl.getAttribute(server, 'state')The getAttribute command returns the value of a single attribute. Example output:
STARTED
Use the AdminControl object for scripted administration
Related Reference
Commands for the AdminControl object