获取进程号:
# 获取tomcat PPID TomcatID=$(ps -ef |grep tomcat |grep -w 'tomcat'|grep -v 'grep'|awk '{print $2}')
echo ${TomcatID}
获取端口号:
#获取端口号if($4>20) 打印出的 端口为80 {if($4<20000)打印的为 127.0.0.1 80 TomcatID=$(ps -ef |grep tomcat |grep -w 'tomcat'|grep -v 'grep'|awk '{print $2}')
port=`netstat -antup |grep LISTEN | grep ${TomcatID} | sed 's/ //g'| awk -F ':' '{if($4>20) {print $4}}'`
echo ${port}