discover_memcached.sh感知memcached

  sre

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 inpids
do
    psinfo=`lsof -p pid|grep txt|grep -v ps|grep -v grep`
    config_path=`echopsinfo|awk -F ' ' '{print 9}'`
    port=`netstat -lnp | greppid/memcached | grep tcp | grep -v "127.0.0.1" | grep "0.0.0.0" | awk '{print 4}'|awk -F ':' '{printNF}'`
    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//\'/\"}`
echoresult

LEAVE A COMMENT

Captcha Code