#! /bin/bash
export LANG=en_US.UTF-8

pids=`ps aux | grep activemq | grep java | grep -v org.apache.catalina.startup.Bootstrap | awk '{print $2}'`
discover_mq_json=""

for pid in $pids
do
    wrapper_pid=`ps aux|grep $pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index($i,"Dwrapper.pid")>1)print $i}}'|head -1|awk -F '=' '{print $2}'`
    if [[ "$wrapper_pid" != "" ]];then
        wrapper_pidfile=`ps aux|grep $wrapper_pid|grep -v grep|grep -v $pid|awk '{for(i=1;i<=NF;++i){if(index($i,"pidfile")>1)print $i}}'|head -1|awk -F '=' '{print $2}'`
        if [ -e "$wrapper_pidfile" ];then
        wrapper_pidfile_path=`dirname "$wrapper_pidfile"`
        cd $wrapper_pidfile_path
    fi
    fi
    target_jar_file=`ps aux|grep $pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index($i,"Dactivemq.home")>1)print $i}}'|head -1|awk -F '=' '{print $2}'`
    pwd=
    if [ -d "$target_jar_file" ];then
        cd $target_jar_file
        pwd=$(echo `pwd`)
        cd conf
        ss=`cat activemq.xml|grep -v '<!\-\-'|grep "openwire"`
        ports=`echo $ss | awk -F ':' '{print $3}' | awk -F '?' '{print $1}' |sed 's/ //g'`
    fi
    if [ "$ports" != "" ];then
        discover_mq_json="$discover_mq_json{'cpname':'activemq','port':'$ports','path':'$pwd','pid':'$pid'},"
    fi

done
result="[${discover_mq_json%,*}]"
result=`echo ${result//\'/\"}`
echo $result

发表评论

您的电子邮箱地址不会被公开。

Captcha Code