Linux端口监控脚本
最近jboss进程经常无缘无故的被Halt,怀疑是某同学远程Debug时,直接点击了Eclipse上的Terminate按钮。但是又没有证据,所以写了一段脚本,专门监控8787端口的占用情况,脚本如下:
#! /bin/sh #Author lanbo.xj LSNPORTS="8787"; INTERVAL=60; iter=0; LOGPATH=$HOME/wlbmywlb/logs; if [ -n $LOGPATH ]; then mkdir -p $LOGPATH; fi; while [ 1 ]; do for port in $LSNPORTS do CCTLST=`netstat -an | grep ".$port" | awk 'BEGIN{OFS="|";}{print $1,$2,$3,$4,$5,$6,$7;}'`; LOGDATE=`date +%Y-%m-%d`; LOGFILE="${LOGPATH}/netstat[${port}]-${LOGDATE}.log"; LOGTIME=`date '+DATE:%Y-%m-%d %H:%M:%S'`; for ns in $CCTLST do NETLST=`echo $ns | awk -F"|" 'BEGIN{OFS=" ";}{print $1,$2,$3,$4,$5,$6,$7;}'`; iter=`expr $iter + 1`; loginfo=`echo "$LOGTIME" ">>" "$NETLST"`; echo "$loginfo" >> $LOGFILE; #echo "$loginfo"; done; echo "$LOGTIME >> Total connections[$port]: " $iter >> $LOGFILE; #echo "Total connections[$port]: " $iter; iter=0; sleep $INTERVAL; done; done;
相关推荐
linuxwcj 2020-10-21
彼岸随笔 2020-10-20
yutou0 2020-10-17
jarrygao 2020-11-02
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
momoku 2020-09-11
ruancw 2020-08-27
TuxedoLinux 2020-08-18
vvu 2020-08-16
downtown 2020-08-11
luvzhan 2020-07-28
maxelliot 2020-06-28
cuixingwudi 2020-06-25
linuxdashencom 2020-06-21
旭灿 2020-06-16
wenjieyatou 2020-06-14