#!/bin/bashexport chknum=1 #shell攪拌存放目錄(輸出日誌文件執行後也存於該目錄)echo 3 > /wls/wls81/shellsyncwhile [ $chknum -ge 0 ]doecho " " >> trace.logmt=`free | tr [:bla ...
#!/bin/bash
export chknum=1
#shell攪拌存放目錄(輸出日誌文件執行後也存於該目錄)
echo 3 > /wls/wls81/shell
sync
while [ $chknum -ge 0 ]
do
echo "-------------------------------------------------------" >> trace.log
mt=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '1p'`
mu=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '2p'`
mf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '3p'`
st=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '9p'`
su=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '10p'`
sf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '11p'`
t=`expr $mt + $st`
u=`expr $mu + $su`
echo "Total Mem: $t"
echo "Used Mem: $u"
R=`expr $mu \* 100 / $mt`
echo "當前記憶體使用率為: $R%" >>trace.log
#開始釋放記憶體(只檢測不操作可把此段斃掉)
if [ $R -gt 80 ]
then
echo "the monitor is more,please clean"
#執行記憶體>80%時清除,以下規則可自行修改
ps -ef|grep java |cut -c 9-15|xargs kill -9
fi
#釋放結束
echo "$R" >> memory.log
echo "記錄時間:" >> trace.log
echo `date` >> trace.log
echo "-------------------------------------------------------" >> trace.log
sleep 24h
done
********************我是帥氣的分割線***********************
腳本搞好後、放入Jenkins設置定時任務。指定time每天跑一次就行啦。再也不怕環境每天因為記憶體問題掛掉了