discover_kafka.sh感知kafka

  sre

#! /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 inpids
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){printi}}}}'|head -1`
    if [ "jar_file" != "" ];then
        lib_path=`dirnamejar_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 : '{printNF}'`

    fi
done

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







LEAVE A COMMENT

Captcha Code