Linux Shell script monitors the running status of WAS (WebSphere Application Server)

Source: Internet
Author: User
Tags websphere application server

Linux Shell script monitors the running status of WAS (WebSphere Application Server)
Principle: You can call the WAS script wsadmin. sh to obtain the instance status.

Operating system version:

[Root] # head-1/etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)

WAS version:
[Root] #/opt/IBM/WebSphere/AppServer/bin/versionInfo. sh | grep-A 3 "Installed Product"
Installed Product
--------------------------------------------------------------------------------
Name IBM WebSphere Application Server-ND
Version 7.0.0.25

Code:

Check_was_state.sh

 
 
  1. #!/bin/ksh
  2. WAS_IP="192.168.222.3"
  3. WAS_USERNAME="wasadmin"
  4. WAS_PASSWORD="wasadmin"
  5. WAS_INSTANCE_NAME="SampleServer1"
  6. WSADMIN="/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh"
  7. FILE_STAT_LOG=was_stat_`date +"%Y%m%d_%H%M%S"`.log
  8. $WSADMIN -lang jython -host $WAS_IP -user $WAS_USERNAME -password $WAS_PASSWORD -f check_was_state.py > $FILE_STAT_LOG 2>&1

  9. grep "${WAS_INSTANCE_NAME}: STARTED" $FILE_STAT_LOG > /dev/null 2>&1
  10. if [ $? == 0 ]; then
  11. echo "$WAS_IP $WAS_INSTANCE_NAME status is OK"
  12. else
  13. echo "$WAS_IP $WAS_INSTANCE_NAME status is not OK"
  14. fi

Check_was_state.py

 
 
  1. import AdminUtilities

  2. # List servers with specified server type
  3. servers = AdminTask.listServers('-serverType APPLICATION_SERVER')

  4. # Convert Jython string to list
  5. servers = AdminUtilities.convertToList(servers)

  6. # Loop through each server in server list
  7. for aServer in servers:
  8. # Obtain server and node names
  9. sname = aServer[0:aServer.find("(")]
  10. nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
  11. runningServer = AdminControl.queryNames("type=Server,node=" + nname + ",name=" + sname + ",*")
  12. if (len(runningServer) > 0):
  13. serverState = AdminControl.getAttribute(runningServer, "state")
  14. else:
  15. serverState = "STOPPED"
  16. # endIf
  17. # Two different states: STARTED, STOPPED
  18. print "%s: %s" % (sname,serverState)
  19. #endFor


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.