discover_swift.sh感知swift

  sre

DvyaPU.jpg

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

pids=`ps aux | grep swift-gateway | grep -v grep | awk '{print 2}'`
discover_swift_json=""

for pid inpids
do
    ip="127.0.0.1"
    ports=`netstat -lntp|grep pid|awk '{print4}'|awk -F ':' '{print NF}'`
    config_path=`ps aux | greppid |grep swift-gateway | grep -v grep |awk -F 'classpath :' '{print 2}' | awk -F '..:' '{print1}'`
    http_port=
    if [ "ports" != "" ];then
        for p inports
        do
           req_url='http://'ip':'p'/'
           http_code=`curl -s --connect-timeout 1 -m 1 req_url -w%{http_code} 2>/dev/null -o /dev/null`
           if [[ "http_code" -gt 199 ]];then
                http_port=p
                break
           fi
        done
        discover_swift_json="discover_swift_json{'cpname':'swift','port':'p','path':'config_path','name':'swift组件模板','flag':'pid'},"
    else
        discover_swift_json="discover_swift_json{'cpname':'swift','path':'config_path','name':'swift组件模板','flag':'pid'},"
    fi
done
result="[{discover_swift_json%,*}]"
result=`echo{result//\'/\"}`
echo $result

LEAVE A COMMENT

Captcha Code