Linux Shell 脚本监控 WebLogic 的运行状态、健康状态、打开的套接字数

#!/bin/bash
CLASSPATH="/opt/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar:$CLASSPATH"
PATH="/usr/java/jdk1.6.0_45/bin:$PATH"

URL="192.168.222.11:7020"
USER_NAME="weblogic"
PASS_WORD="weblogic1"
DOMAIN_NAME="MedRecDomain"
SERVER_NAME="MedRecAdmSvr"

STATE_ALL=$(java weblogic.Admin -url $URL -username $USER_NAME -password $PASS_WORD get -pretty -mbean "$DOMAIN_NAME:Location=$SERVER_NAME,Name=$SERVER_NAME,Type=ServerRuntime")

# Check WebLogic instance running status
echo "$STATE_ALL" | grep -q "State: RUNNING"
if [ $? == 0 ]; then
    echo "$URL $DOMAIN_NAME $SERVER_NAME running status is OK"
else
    echo "$URL $DOMAIN_NAME $SERVER_NAME running status is not OK"
fi

# Check WebLogic instance health status
echo "$STATE_ALL" | grep -q "State:HEALTH_OK"
if [ $? == 0 ]; then
    echo "$URL $DOMAIN_NAME $SERVER_NAME health status is OK"
else
    echo "$URL $DOMAIN_NAME $SERVER_NAME health status is not OK"
fi

# Check WebLogic instance open sockets number
SOCKET_MAX=200
SOCKET_NOW=$(echo "$STATE_ALL" | awk '/OpenSocketsCurrentCount/{print $2}')
if [ x$SOCKET_NOW == x ]; then
    echo "$URL $DOMAIN_NAME $SERVER_NAME open sockets number is not OK: fail to get"
else
    if [ $SOCKET_NOW -gt $SOCKET_MAX ]; then
        echo "$URL $DOMAIN_NAME $SERVER_NAME health status is not OK: $SOCKET_NOW greater than $SOCKET_MAX"
    else
        echo "$URL $DOMAIN_NAME $SERVER_NAME health status is OK: $SOCKET_NOW not greater than $SOCKET_MAX"
    fi
fi

 

你可能感兴趣的:(shell编程)