5fc8a55e2139f108.jpg_fo742.jpg

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

pids=`ps aux|grep mongod|grep -v java |grep -v solr|grep -v grep|grep -v ps | awk '{print $2}'`
discover_mongo_json=""

for pid in $pids
do
    ports=`netstat -lntp|grep $pid|awk '{print $4}'|awk -F ':' '{print $NF}'`
    psinfo=`lsof -p $pid|grep txt|head -n 1 |grep -v ps|grep -v grep`
    config_path=`echo $psinfo|awk -F ' ' '{print $9}'`
    p_number=`echo $ports|awk '{print NF}'`
    if [ "$p_number" -gt 1 ];then
        ports=$ports|awk '{if($1>$2){print $2}else{print $1}}'
    else
        ports=$ports
    fi

    if [ "$ports" != "" ];then
        for p in $ports
        do
            discover_mongo_json="$discover_mongo_json{'cpname':'mongo','port':'$p','path':'${config_path%*mongod}','name':'MongoDB组件模板','flag':'$pid'},"
        done
    else
        discover_mongo_json="$discover_mongo_json{'cpname':'mongo','path':'${config_path%*mongod}','name':'MongoDB组件模板','flag':'$pid'},"
    fi
done
result="[${discover_mongo_json%,*}]"
result=`echo ${result//\'/\"}`
echo $result









发表评论

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

Captcha Code