discover_zookeeper.sh感知zookeeper

  sre

k Dvyw24.jpg

“`bash
#! /bin/bash

export LANG=en_US.UTF-8

pids=ps aux|grep org.apache.zookeeper.server.quorum.QuorumPeerMain|grep -v grep|awk '{print $2}'

for pid in $pids
do
#通过配置文件读取端口号
port=
conf_file=ps aux ww|grep pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index(i,".cfg")>1)print $i}}'|head -1
if [ -n “$conf_file” ];then
port=sed '/clientPort/!d;s/.*=//' $conf_file|tr -d '\r'
else
#通过 netstat 读取端口号
ports=netstat -lntp|grep pid|awk '{print4}'|awk -F ':' '{print $NF}'
p_number=echo $ports|awk '{print NF}'
if [ “p_number” -gt 1 ];then
port=
ports|awk ‘{if(1>2){print 2}else{print1}}’
else
port=$ports
fi
fi

path=
jar_file=`ps aux|grep pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index(i,"zookeeper")>1&&index(i,"lib")>1)printi}}'|awk -F ':' '{for(i=1;i<NF;++i){if(index(i,"lib")>1&&index(i,"build")<1){print i}}}'|head -1`
if [ "jar_file" != "" ];then
        lib_path=`dirname jar_file`
        cdlib_path/..
        path=`pwd`      
fi
discover_zookeeper_json="discover_zookeeper_json{'cpname':'zookeeper','port':'port','path':'path','name':'Zookeeper组件模板','flag':'pid'},"

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

“`

LEAVE A COMMENT

Captcha Code