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

#ps aux | grep -v grep | grep -v ps.sh|grep ./tomcat | grep Dcatalina.base=
pids=`ps aux |grep -w 'canal'|grep -v grep |grep -v 'discover_canal.sh'| awk '{print $2}'`
discover_canal_json=""

#遍历pids
for pid in $pids
do 
    port=`netstat -lntp|grep $pid|head -1|awk '{print $4}'|awk -F ':' '{print $NF}'`
    catalina_base=`ps aux |grep -w $pid|grep -v grep |grep -v 'discover_canal.sh'| awk '{for(i=1;i<NF;++i){if(index($i,"Dcanal.conf") != 0) print $i}}'`
    catalina_base=`echo $catalina_base|awk -F '=' '{print $2}'`
    path=`echo ${catalina_base%bin*}`
    if [[ $path != "" ]];then
        canal_info="{'cpname':'canal','port':'$port','path':'$path','name':'Canal组件模板','flag':'$pid'},"
        discover_canal_json="$discover_canal_json$canal_info"
    fi
done

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

发表评论

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

Captcha Code