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 inpids
do
    ports=`netstat -lnp | grep pid/nginx | grep tcp | grep -v "127.0.0.1" | head -n 1 | awk '{print4}'|awk -F ':' '{print NF}'`
    config_path=`ls -l /proc/pid/exe | awk '{for(i=1;i<=NF;i++){if(i ~ /nginx/) printi}}'`
    if [ "ports" != "" ];then
        for p inports
        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//\'/\"}`
echoresult







发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code