#!/bin/shwhile [ true ]; do #查詢是否有8899正在運行的進程netstat -an|grep 8899if [ $? -ne 0 ]thennowtime=$(date +%Y-%m-%d\ %H:%M:%S)echo "end process.....">> issu ...
#!/bin/sh
while [ true ]; do
#查詢是否有8899正在運行的進程
netstat -an|grep 8899
if [ $? -ne 0 ]
then
nowtime=$(date +%Y-%m-%d\ %H:%M:%S)
echo "end process.....">> issuemonitor.bat
#check memory used rate
#|代表同時滿足後面的信息 awk '{print $2}' 代表顯示第二列 |sed -n '2p' 代表顯示第2行
totalMemory=$(free -m|awk '{print $2}'|sed -n '2p')
##|代表過濾掉後面的信息 awk '{print $3}' 代表顯示第三列 |sed -n '3p' 代表顯示第3行
usedMemory=$(free -m|awk '{print $3}'|sed -n '3p')
freeMemory=$(free -m|awk '{print $4}'|sed -n '3p')
usedPerMemory=$(awk 'BEGIN{printf "%.0f",('$usedMemory'/'$totalMemory')*100}')
freePerMemory=$(awk 'BEGIN{printf "%.0f",('$freeMemory'/'$totalMemory')*100}')
minfo="totalMemory:$totalMemory MB,used:$usedMemory MB,free:$freeMemory MB,usedPercent:$usedPerMemory%,freePrecent:$freePerMemory%"
echo "$nowtime $minfo Memory used" >> issuemonitor.bat
#check cpu usedrate
top -m >> issuemonitor.bat
break
else
nowtime=$(date +%Y-%m-%d\ %H:%M:%S)
echo $nowtime >> issuemonitor.bat
echo "runing....." >> issuemonitor.bat
#代表8899下的所有的進程號 grep -v 是反向查找的意思 grep -v "$0" 代表不包含第一行
ID=`lsof -i:8899 | grep -v "$0"|grep -v "PID" | grep -v "grep" | awk '{print $2}'`
for id in $ID
do
jstack $id >> issuemonitor.bat
done
fi
sleep 5
done