Use shell scripts on Linux to view memory conditions (ultra-practical), linuxshell

Source: Internet
Author: User

Use shell scripts on Linux to view memory conditions (ultra-practical), linuxshell

#! /Bin/bash
Export chknum = 1

# Shell mixing directory (the output log file is also stored in this directory after execution)
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 usage: $ R %"> trace. log

# Start to release the memory (only detect and delete this segment if no operation is performed)
If [$ R-gt 80]
Then
Echo "the monitor is more, please clean"

# Clear when the memory is executed> 80%. You can modify the following rules.
Ps-ef | grep java | cut-c 9-15 | xargs kill-9
Fi

# Release ended

Echo "$ R"> memory. log
Echo "record time:"> trace. log
Echo 'date'> trace. log
Echo "-------------------------------------------------------"> trace. log
Sleep 24 h
Done

 

 

 

 

* ****************** I am a handsome splitting line *************** ********

 

After the script is completed, add Jenkins to set the scheduled task. Set the time to run once a day. I am no longer afraid that the Environment crashes due to memory problems every day.

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.