Use the shell to write a script that has more than 80% mail alerts on the disk

Source: Internet
Author: User
Tags cpu usage disk usage

Method 1:

Monitoring disk or CPU exceeding a certain value mail alert script:

[email protected] scripts]# cat check.sh

#!/bin/bash

Lang=en_us. UTF-8

cpuused= ' Top-n 1|awk-f ' [,%]+ ' nr==3 {print100-$11} '

diskused=$ (df-h|awk-f ' [%]+ '/\/$/{print $} ')

Logfile=/tmp/jk.log

function Sendmail () {

Mail-s "Monitoring alarm" 1665***[email protected] < $logFile

}

function Check () {

If [' Echo ' $cpuUsed >80 "|BC '-eq 1-o $diskUsed-ge

echo "CPU Usage: ${cpuused}%, disk Usage: ${diskused}%" > $logFile

Sendmail

Fi

}

function Main () {

Check

}

Main


Method 2:

Monitor the disk space size and notify the script by mail:

#!/bin/bash

D= ' Df-h|grep "/dev/sda6" |awk ' {print int ($)} '

Logfile=/tmp/jk.log

function Sendmail () {

Mail-s "Monitoring alarm" 1665***[email protected] < $logFile

}

function Check () {

If

[$d-gt];then

echo "Current hard drive is ${d}%" > $logFile

Sendmail

Else

echo "Hard drive Enough"

Fi

}

function Main () {

Check

}

Main


This article is from the "one small step per day" blog, so be sure to keep this source http://fenyuer.blog.51cto.com/11265169/1917026

Use the shell to write a script that has more than 80% mail alerts on the disk

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.