discover_redis感知redis

  sre

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


pids=`ps aux | grep -v grep | grep -v ps.sh|grep redis-server | grep : | grep -v defunct | awk '{print 2}'`
discover_redis_json=""
PORT=
CURSTR=(ps aux | grep "1" | grep -v grep)
curStr=(echo CURSTR | awk '{cc=index(0,"redis-server");if(cc>-1){print substr(0,cc);}}')
UW=(echo curStr| grep ":")

for pid inpids
do
    if [[ "UW" != "" ]];then
        PORT=(netstat -lnp | grep -v grep|grep redis-s | grep pid | awk '{print4}' | awk -F ':' '{print (NF)}' |head -1)
    fi
    if [[ "PORT" = "" ]];then
        continue
    else
        config_path=`ls -l /proc/pid/exe | awk '{for(i=1;i<=NF;i++){if(i ~ /redis-server/) print i}}'`
        discover_redis_json="discover_redis_json{'cpname':'redis','port':'PORT','path':'{config_path%*redis-server}','name':'Redis组件模板','flag':'pid'},"
    fi
    #PORT=`sed 's/^[\s]*//g' | sed 's/[\s]&*//g'`
done
result="[{discover_redis_json%,*}]"
result=`echo {result//\'/\"}`
echoresult




LEAVE A COMMENT

Captcha Code