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 in $pids
do
    ip="127.0.0.1"
    ports=`netstat -lntp|grep $pid|awk '{print $4}'|awk -F ':' '{print $NF}'`
    config_path=`ps aux | grep $pid |grep swift-gateway | grep -v grep |awk -F 'classpath :' '{print $2}' | awk -F '..:' '{print $1}'`
    http_port=
    if [ "$ports" != "" ];then
        for p in $ports
        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

发表评论

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

Captcha Code