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

pids=`ps aux|egrep "kafka|kafka.Kafka"|grep -v grep|grep -v zookeeper.properties | awk '{print $2}'`

port=
pwd=

for pid in $pids
do
    jar_file=`ps aux|grep $pid|grep -v grep|grep -v zookeeper.properties|awk '{for(i=1;i<=NF;++i){if(index($i,".jar")>=1){print $i}}}'|awk -F ':' '{for(i=1;i<NF;++i){if(index($i,".jar")>1){if(index($i,"kafka")>=1){print $i}}}}'|head -1`
    if [ "$jar_file" != "" ];then
        lib_path=`dirname $jar_file`
        cd $lib_path/../
        pwd=`pwd`/
        if [ "" != $pwd ];then
            config_port=`grep "port=" config/server.properties|grep -v '#'|awk -F '=' '{print $2}'`
            if [ "$config_port" != "" ];then
                result="$result,{'cpname':'kafka','port':'$config_port','path':'$pwd','name':'Kafka组件模板','flag':'$pid'}"
            else
                result="$result,{'cpname':'kafka','port':'9092','path':'$pwd','name':'Kafka组件模板','flag':'$pid'}"
            fi
        else
            result=""
        fi
        #config_port=`sed  '/#listeners=/!d;s/.*=//' config/server.properties|tr -d '\r'|awk -F : '{print $NF}'`

    fi
done

result="[${result#*,}]"
result=`echo ${result//\'/\"}`
echo $result







发表回复

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

Captcha Code