First you may create secure key files to avoid using plain text uname and password for weblogic.
Step1:
Run WLST --> /opt/admin/fmw/oracle_common/common/bin/wlst.sh
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline>connect('weblogic','welcome1',url='t3://localhost:7001')
wls:/myDomain/serverConfig> storeUserConfig('/tmp/myUserConfigFile','/tmp/myUserKeyFile')
wls:/myDomain/serverConfig> exit()
Step2:
File name: getAllServerStatus.py
import sys
import os
connect(userConfigFile='myUserConfigFile', userKeyFile='myUserKeyFile', url='t3://localhost:7001')
domainRuntime()
cd('ServerRuntimes')
sServers=domainRuntimeService.getServerRuntimes()
for sServer in sServers:
serverName=sServer.getName();
print '###' , serverName,'State is:', sServer.getState()
disconnect()
exit()
Step3:
FileName: getAllServerState_wls.sh
#!/bin/ksh
echo "Getting All Servers State......"
/opt/admin/fmw/oracle_common/common/bin/wlst.sh getAllServerStatus.py > /tmp/allServerStatus.log
cat /tmp/allServerStatus.log | grep -i state
exit 0
Example Run:
./getAllServerState_wls.sh
Getting All Servers State......
### AdminServer State is: RUNNING
### my_server1 State is: RUNNING
### my_server2 State is: RUNNING
Step1:
Run WLST --> /opt/admin/fmw/oracle_common/common/bin/wlst.sh
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline>connect('weblogic','welcome1',url='t3://localhost:7001')
wls:/myDomain/serverConfig> storeUserConfig('/tmp/myUserConfigFile','/tmp/myUserKeyFile')
wls:/myDomain/serverConfig> exit()
Step2:
File name: getAllServerStatus.py
import sys
import os
connect(userConfigFile='myUserConfigFile', userKeyFile='myUserKeyFile', url='t3://localhost:7001')
domainRuntime()
cd('ServerRuntimes')
sServers=domainRuntimeService.getServerRuntimes()
for sServer in sServers:
serverName=sServer.getName();
print '###' , serverName,'State is:', sServer.getState()
disconnect()
exit()
Step3:
FileName: getAllServerState_wls.sh
#!/bin/ksh
echo "Getting All Servers State......"
/opt/admin/fmw/oracle_common/common/bin/wlst.sh getAllServerStatus.py > /tmp/allServerStatus.log
cat /tmp/allServerStatus.log | grep -i state
exit 0
Example Run:
./getAllServerState_wls.sh
Getting All Servers State......
### AdminServer State is: RUNNING
### my_server1 State is: RUNNING
### my_server2 State is: RUNNING