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

pids=`ps  aux |grep org.elasticsearch.bootstrap.Elasticsearch|grep -v grep|awk '{print 2}'`
#ip=`ifconfig 2>/dev/null|sed -n 2p|awk  '{ print2 }'|awk -F : '{ print 2 }'`
ip=`ip addr | grep 'state UP' -A2 | head -n3|tail -n1 | awk '{print2}' | cut -f1 -d '/'`
discover_elasticsearch_json=""

for pid in pids
do     if [pid ];then
        pwd=`ps aux|grep pid|grep java|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index(i,"Des.path.home")>=1){print i}}}'|awk -F '=' '{print2}'|head -1`
        ports=`netstat -lntp|grep pid|awk '{print4}'|awk -F ':' '{print NF}'`
        elasticsearch_info=
        for p inports
        do
            req_url='http://'ip':'p'/'
            response_code=`curl -s  req_url -w%{http_code} 2>/dev/null -o /dev/null`
            if [[ "response_code" -gt 199 ]];then
                elasticsearch_info="{'cpname':'elasticsearch','port':'p','path':'pwd','name':'Elasticsearch组件模板','flag':'pid'},"
                break
            fi
        done
    else
        echo "miss argument pid!" >2
    fi
    discover_elasticsearch_json="discover_elasticsearch_jsonelasticsearch_info"
done

result="[{discover_elasticsearch_json%,*}]"
result=`echo {result//\'/\"}`
echoresult

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code