5fc8a9c66a6cf8550.jpg_fo742.jpg

#! /bin/bash
export LANG=en_US.UTF-8
pids=`ps aux | grep memcached | grep -v grep | grep -v discover_memcached.sh | awk '{print $2}'`
discover_memcached_json=""

for pid in $pids
do
    psinfo=`lsof -p $pid|grep txt|grep -v ps|grep -v grep`
    config_path=`echo $psinfo|awk -F ' ' '{print $9}'`
    port=`netstat -lnp | grep $pid/memcached | grep tcp | grep -v "127.0.0.1" | grep "0.0.0.0" | awk '{print $4}'|awk -F ':' '{print $NF}'`
    path=${config_path%*memcached}
    if [[ "$path" == "/bin/bash" ]];then
        continue
    fi
    if [ "$port" != "" ];then
        discover_memcached_json="$discover_memcached_json{'cpname':'memcached','port':'$port','path':'$path','name':'Memcached组件模板','flag':'$pid'},"
    else
        continue
    fi

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

发表评论

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

Captcha Code