5fc7dc625ed603016.jpg_fo742.jpg

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


pids=`ps aux | grep -v grep | grep -v ps.sh|grep /nginx | awk '{print $2}'`
discover_nginx_json=""

for pid in $pids
do
    ports=`netstat -lnp | grep $pid/nginx | grep tcp | grep -v "127.0.0.1" | head -n 1 | awk '{print $4}'|awk -F ':' '{print $NF}'`
    config_path=`ls -l /proc/$pid/exe | awk '{for(i=1;i<=NF;i++){if($i ~ /nginx/) print $i}}'`
    if [ "$ports" != "" ];then
        for p in $ports
        do
            discover_nginx_json="$discover_nginx_json{'cpname':'nginx','port':'$p','path':'${config_path%*nginx}','name':'Nginx组件模板','flag':'$pid'},"
        done
    else
        discover_nginx_json="$discover_nginx_json{'cpname':'nginx','path':'${config_path%*nginx}','name':'Nginx组件模板','flag':'$pid'},"
    fi

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







发表评论

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

Captcha Code