Use shell scripts on Linux to view memory conditions (super-practical)

Source: Internet
Author: User

#!/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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.