#!/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每天跑一次就行啦。再也不怕环境每天因为内存问题挂掉了