Shell script Instance-memory disk usage warning

Source: Internet
Author: User
Tags disk usage

1, disk use warning and send mail

#!usr/bin/bash

#df-th|grep '/$ ' This is the record that gets the memory used

#后面两句是获取内存的使用率

disk= ' df-th|grep '/$ ' |awk ' {print $ (NF-1)} ' |awk-f '% ' ' {print '} '

Mail_user=natasha

If [$disk-ge];then

echo "' Date +%f-%h ' disk:${disk}%" |mail-s "Disk war ..." $mail _user

Fi

2, Memory usage warning and sending mail

#!/usr/bin/bash

Mem_used= ' Free-m|grep ' ^mem: ' |awk ' {print $} '

Mem_total= ' Free-m|grep ' ^mem: ' |awk ' {print $} '

mem_per=$ ((mem_used*100/mem_total))

War_file=/tmp/mem_war.txt

RM-RF $war _file# This step is to prevent this file from being present the next time you execute the script

If [$mem _per-ge 2];then

echo "' Date +%f-%h ' memory:${mem_per}%" > $war _file

Fi

If [-F $war _file];then

Mail-s "Mem war ..." Root < $war _file

Fi

Author Profile:
Chen Zhike (Headline number: the strong twist of the melon is not delicious currently working in China's largest android application software company, as a senior engineer , now the company is a PHP development engineer, Python development engineer, senior Operations engineer, the public number "pencil school" operation and maintenance of content co-author. *
Pencil Study Garden : It resource sharing | Knowledge sharing, being the primary programmer's beacon

Shell script Instance-memory disk usage warning

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.