(turn) Develop monitoring Linux memory Shell scripts

Source: Internet
Author: User

Original: http://blog.csdn.net/timchen525/article/details/76474017

Problem Scenario:

Develop the shell script to determine the size of the system's remaining memory, if less than 100MB, the message to the system administrator, and the script into the system scheduled tasks, that is, every 3 minutes to perform a check.

In two steps:

First step: scripting

The script memory_mon.sh is as follows:

[Plain]View PlainCopy
    1. #!/bin/bash
    2. Freemem= ' Free-m|awk ' nr==3 {print $NF} ' #获取系统当前的内存值, assign to variable Freemem
    3. chars= "Current memory is$freemem." #定义字符串CHARS变量, as output and for message body use
    4. If [$FreeMem-lt 100]
    5. Then
    6. echo $CHARS |tee/tmp/messages.txt #屏幕输出提示 and write to file
    7. Mail-s "' Date +%f-%t ' $CHARS" [email protected]</tmp/messages.txt
    8. Fi

Analysis:

free-m is displayed in megabytes, nr==3 represents the third row, $NF represents the last column. The specific meanings of the individual parameters of free refer to my blog post: theLinux free command analyzes memory usage .

The tee is output to both the Echo $CHARS on the standard output device and outputs the results to a file.

mail-s usage refer to my blog: Linux outbound Mail feature.

Step Two: timed task crontab

[Plain]View PlainCopy
    1. */3 * * * */bin/sh/root/memory_mon.sh&>/dev/null

(turn) Develop monitoring Linux memory Shell scripts

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.