discover_hbase.sh发现hbase

  sre

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


pids=`ps aux | egrep "HMaster|HRegionServer" | grep -v grep | grep -v "uoamp" | grep -v ps.sh | awk '{print 2}'`
discover_hbase_json=""

for pid inpids
do
    port=`netstat -lnp | grep pid/ | grep tcp | grep LISTEN | head -n 1 | awk '{print4}'|awk -F ':' '{print NF}'`
    if [ "port" != "" ];then
        path=`ps aux|grep pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index(i,"Dhbase.home.dir")>1)print i}}'|head -1|awk -F '=' '{print2}'`
        discover_hbase_json="discover_hbase_json{'cpname':'hbase','port':'port','flag':pid,'name':'Hbase组件模板','path':'path'},"
    fi
done
result="[{discover_hbase_json%,*}]"
result=`echo{result//\'/\"}`
echo $result

LEAVE A COMMENT

Captcha Code