#!/bin/bash
Export Chknum=1
#shell搅拌存放目录 (The output log file is also stored in the directory after it is executed)
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 "Current memory utilization: $R%" >>trace.log
#开始释放内存 (only detects the operation can kill the paragraph)
If [$R-GT 80]
Then
echo "The monitor is More,please clean"
#执行内存 >80%, the following rules are self-modifying
Ps-ef|grep java |cut-c 9-15|xargs kill-9
Fi
#释放结束
echo "$R" >> Memory.log
echo "Recording time:" >> Trace.log
echo ' Date ' >> trace.log
echo "-------------------------------------------------------" >> Trace.log
Sleep 24h
Done
I'm a handsome split-line ***********************
After the script is done, put Jenkins to set a timed task. Specify time to run every day. No more fear of the environment every day because of the memory problem hangs out
Use shell scripts on Linux to view memory conditions (super-practical)