"Sehll learning" Linux operations a simple shell script monitors system memory

Source: Internet
Author: User

After learning the shell script to get started, slowly try to write some scripts to practice practiced hand, in this first simple learning to write a system memory monitoring.

1, first of all to determine the need to take a look at the memory usage values, you can use the free command to operate

650) this.width=650; "border=" 0 "src="/e/u261/themes/default/images/spacer.gif "style=" border:1px solid RGB ( 221,221,221) Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat 50% 50%; "alt=" Spacer.gif "/> free-m Display
650) this.width=650; "alt=" Linux Ops shell script monitors memory-linux operations "src=" http://114share.com/uploads/allimg/160225/ 1-1602251i215632.png "style=" border:0px;width:400px;height:53px; "/>

Generally in monitoring memory is we are intercepting the third line (-/+ Buffers/cache) value. Once determined, you can use the pipe line and the grep command to get this value.

free-m | grep-| awk ' {print $4} '

Get to his value for 858

grep--It's a match for what you want to pick, and it's less familiar to learn about grep and awk commands.

2. Then decide whether this value is lower than the peak we want to judge and send an email alert. Such as: Peak is 900

Below write a simple script, here first not send the message just simple to judge him below the setting, output as a hint message.

Script content:


  1. #!/bin/bash

  2. nei=`free -m |grep -|awk ‘{print $4}‘`

  3. [ $nei -lt 900 ]&&{

  4. echo "你的内存使用已经小于峰值"

  5. exit 0

  6. }

A very simple script.


"Sehll learning" Linux operations a simple shell script monitors system memory

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.