统计项目环境信息

echo "------------------统计计数-----------------------------"
echo ""
echo ""
#使用端口数量
DKS=$(ss -ntlp |grep pid  |grep -v grep |awk '{print $4}' |grep -v 127.0.0.1 | awk -F":" '{print $NF}' |wc -l)
echo "使用端口数量 $DKS"
#具体端口
echo "具体端口如下:"
ss -ntlp |grep pid  |grep -v grep |awk '{print $4}' |grep -v 127.0.0.1 | awk -F":" '{print $NF}' |sort -n |uniq |xargs
#项目进程数量 
JCS=$(ss -ntlp |grep -v ssh|grep pid  |grep -v grep |awk -F"," '{print $2}'| sort | uniq|awk -F"=" '{print $2}'|uniq |sort |wc -l)
echo "项目进程数量 $JCS"
#项目进程详细信息
echo "项目进程详细信息如下:"
#!/bin/bash
HLIST=$(ss -ntlp |grep -v ssh|grep pid  |grep -v grep |awk -F"," '{print $2}'| sort | uniq|awk -F"=" '{print $2}'|uniq |sort )
for IP in $HLIST
do
ps -ef|grep $IP |grep -v grep|grep -v print|sort 
done


echo "------------------统计tomcat-----------------------------"
echo ""
echo ""
#!/bin/bash
#检测tomcat 路径及端口
HLIST=$(ss -ntlp |grep -v ssh|grep pid  |grep -v grep |awk -F"," '{print $2}'| sort | uniq|awk -F"=" '{print $2}'|uniq |sort )
for IP in $HLIST
do
#筛选 tomcat 路径
TOMPA=$(ps -ef|grep $IP |grep -v grep|awk -F\-jar '{print $NF}'|grep "tomcat" | awk -F"=" '{print $2}' | awk -F"conf" '{print $1}'|grep -v print|sort ) 
if [ -z  $TOMPA ] ; then
SYBS=SYBS
else
WPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep -v 127.0.0.1 | awk -F":" '{print $NF}' |xargs)
NPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep  127.0.0.1 | awk -F":" '{print $NF}' |xargs)
echo "此进程使用到的内部端口为 $NPORT ,使用到的外部端口为 $WPORT"
echo "部署的tomcat 具体路径是 $TOMPA "
fi
done

echo "------------------统计jar-----------------------------"
echo ""
echo ""
#!/bin/bash
#筛选jar 路径及对应端口
HLIST=$(ss -ntlp |grep -v ssh|grep pid  |grep -v grep |awk -F"," '{print $2}'| sort | uniq|awk -F"=" '{print $2}'|uniq |sort )
for IP in $HLIST
do
#筛选jar 路径
TOMPA=$(ps -ef|grep $IP |grep "\-jar" |grep -v grep|awk -F\-jar '{print $NF}'|grep -v print|sort ) 
if [ -z  $TOMPA ] ; then
SYBS=SYBS
else
WPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep -v 127.0.0.1 | awk -F":" '{print $NF}' |xargs)
NPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep  127.0.0.1 | awk -F":" '{print $NF}' |xargs)
echo "此进程使用到的内部端口为 $NPORT ,使用到的外部端口为 $WPORT"
echo "部署的jar 具体路径是 $TOMPA "
fi
done

echo "------------------统计其他-----------------------------"
echo ""
echo ""
#!/bin/bash
#筛选除tomcat 和jar以外的进程及端口
HLIST=$(ss -ntlp |grep -v ssh|grep pid  |grep -v grep |awk -F"," '{print $2}'| sort | uniq|awk -F"=" '{print $2}'|uniq |sort )
for IP in $HLIST
do
#筛选除tomcat 和jar以外的进程及端口
TOMPA=$(ps -ef|grep $IP |grep -v "\-jar" |grep -v "tomcat" |grep -v grep|awk -F " "  '{for (i=8;i<=NF;i++)printf("%s ", $i);print ""}' |grep -v print|sort ) 
if [ -z  "$TOMPA" ] ; then
SYBS=SYBS
else
WPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep -v 127.0.0.1 | awk -F":" '{print $NF}' |xargs)
NPORT=$(ss -ntlp|grep $IP |grep -v grep |awk '{print $4}' |grep  127.0.0.1 | awk -F":" '{print $NF}' |xargs)
echo "此进程使用到的内部端口为 $NPORT ,使用到的外部端口为 $WPORT"
echo "部署的进程具体是 $TOMPA "
fi
done
posted @ 2021-01-28 15:43  鸣昊  阅读(41)  评论(0编辑  收藏  举报