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


pid=`ps aux | grep -v grep | grep -v ps.sh | grep solr | grep -v discover_solr.sh | awk '{print $2}' `
ip=`ifconfig 2>/dev/null|sed -n 2p|awk  '{ print $2 }'|awk -F : '{ print $2 }' `
if [[ "$ip" == "" ]];then
    ip=`ifconfig 2>/dev/null|sed -n 2p|awk  '{ print $2 }'`
fi

http_port=
discover_solr_json=""

for pid in $pid
do
    ports=`netstat -lntp|grep $pid|awk '{print $4}'|awk -F ':' '{print $NF}'`
    for p in $ports
    do
       req_url='http://'$ip':'$p'/'
       http_code=`curl -s $req_url -w%{http_code} 2>/dev/null -o /dev/null`
       if [[ "$http_code" -gt 199 ]];then
            http_port=$p
            break
       fi
    done
    path=`ps aux|grep $pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index($i,"Dcatalina.home")>1)print $i}}'|head -1|awk -F '=' '{print $2}'`
    if [[ "$path" == "" ]];then
        path=`ps aux|grep $pid|grep -v grep|awk '{for(i=1;i<=NF;++i){if(index($i,"Dsolr.install.dir")>1)print $i}}'|head -1|awk -F '=' '{print $2}'`
    fi
    discover_solr_json="$discover_solr_json{'cpname':'solr','port':'$http_port','name':'Solr组件模板','path':'$path','flag':'$pid'},"
done

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

发表评论

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

Captcha Code