Linux Shell脚本监控WAS的运行状态

系统 Linux
通过调用WAS自带的脚本wsadmin.sh来获取实例的状态

原理:通过调用 WAS 自带的脚本 wsadmin.sh 来获取实例的状态

操作系统版本:

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

WAS 版本:

[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
 

代码:

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 

 原文链接:http://blog.chinaunix.net/uid-17176286-id-4409384.html

责任编辑:牛小雨 来源: Shell_HAT的博客
相关推荐

2011-04-01 16:23:14

Cacti监控Nginx

2012-03-06 09:20:02

ibmdw

2020-07-03 07:59:01

Linux服务systemd

2011-10-10 14:42:22

SQL Server

2020-09-23 06:00:04

ShellLinux邮件监控

2013-09-04 09:59:49

监控 Shell 脚本

2009-08-28 16:16:02

线程运行状态

2013-08-30 10:25:22

Shell主机监控

2022-05-02 18:29:35

bashshellLinux

2022-06-09 08:07:15

Shell脚本Linux

2023-10-10 09:19:59

日志Java

2009-12-25 09:49:32

LinuxShell编程运行Shell程序

2014-05-16 11:38:27

Shell 脚本监控

2010-10-13 09:45:50

Linux监控脚本

2021-02-15 17:29:46

LinuxShell脚本

2019-08-28 06:58:06

Linux监控脚本Shell

2019-08-23 06:22:47

LinuxShell监控脚本

2020-05-26 10:28:36

shell脚本单例运行

2020-05-26 08:04:24

Shell脚本单例

2017-08-11 17:20:07

LinuxShell
点赞
收藏

51CTO技术栈公众号