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


pids=`ps aux |grep mysqld|grep -v mysqld_safe| grep -v grep | grep -v ps.sh | grep -v dump | awk '{print $2}'`
discover_mysql_json=""


for pid in $pids
do
    ports=`netstat -lntp|grep $pid/mysqld | awk '{print $4}'|awk -F ':' '{print $NF}'`
    config_path=`ls -l /proc/$pid/exe | awk '{for(i=1;i<=NF;i++){if($i ~ /mysqld/) print $i}}'`
    #echo "${config_path%*mysqld}"
    for port in $ports
    do
#      if [ "$port" = "3306" ];then
            discover_mysql_json="$discover_mysql_json{'cpname':'mysql','port':'$port','path':'${config_path%*mysqld}','name':'Mysql组件模板','flag':'$pid'},"
#          break;
#      fi
    done    
done
result="[${discover_mysql_json%,*}]"
result=`echo ${result//\'/\"}`
echo $result

发表回复

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

Captcha Code