查看当前服务器内所有JAVA进程的端口
脚本使用
oldifs="$IFS"
IFS=$'\n'
for i in `jps|grep -v Jps`; do
pid=`echo $i|awk '{print $1}'`
pname=`echo $i|awk '{print $2}'`
pport=`ss -ntlp |grep $pid|sed -r -e "s#.*:::([0-9]{3,5}).*#\1#g"`
echo "$pid:$pname:$pport"
done
IFS=$oldifs
命令行使用(jps)
echo;echo "==========";echo;oldifs="$IFS";IFS=$'\n';for i in $(jps|grep -v Jps);do echo -n -e "PID :\t";echo $i|awk '{print $1}';echo -n -e "NAME:\t";echo $i|awk '{print $2}';echo -n -e "PORT:\t";echo $(ss -ntlp|grep $(echo $i|awk '{print $1}') |sed -r "s#.*:::([0-9]{3,5}).*#\1#g");echo;done;IFS=$oldifs;echo "==========";echo;
命令行使用(ps)
echo;echo "==========";echo;oldifs="$IFS";IFS=$'\n';for i in $(ps -ef|grep -v grep|grep java);do echo -n -e "PID :\t";echo $i|awk '{print $2}';echo -n -e "NAME:\t";echo $i|sed -r "s#.* (.*\.jar).*#\1#g";echo -n -e "PORT:\t";echo $(ss -ntlp|grep $(echo $i|awk '{print $2}') |sed -r "s#.*:::([0-9]{3,5}).*#\1#g");echo;done;IFS=$oldifs;echo "==========";echo;