Linux automatically detects disk space scripts and automatically reports

Source: Internet
Author: User


Idle egg Pain wrote a code

Example 1

The code is as follows Copy Code

#!/bin/sh
max=99
list=$ (Df-h|awk ' {print $} ' |sed ' s/%//g ' |sed '/[a-za-z]/d ')

Mailto= "135********@139.com"
Subject= "$ (hostname) ' s partition alert"
Content= "$ (hostname) ' s used detail:n $ (df-h |awk ' {print$6,$5} ') ntime:$ (date-d today + '%y-%m-%d%h:%m:%s ')"

For PERCENT in $LIST; Todo
If [$PERCENT-gt $MAX]; Then
Echo-e "MAX Used: $PERCENT%n$content" | Mail-s "$subject" $mailto
Exit
Fi
Done

Exit

We can automatically join the scheduled task to execute the

Example 2 (function: Monitor disk space size and automatically report)

The code is as follows Copy Code

#!/bin/sh

#make by ItBit

Init ()

{

ipadd= ' Ifconfig|grep 172.18|awk ' {print $} ' |sed ' s/addr://g ';

Nowtime= ' Date +%f-%h:%m ';

Mailto= "";

mail_sub= "!**report-disk Capacity the **!";

Tmpfile=/tmp/iamatmpfile.tmp

}

Mhead ()

{

echo "" > $tmpfile;

echo "From: $IPADD" >> $tmpfile

echo "State:report" >> $tmpfile

echo "Reportby:$0" >> $tmpfile

echo "DateTime: $NOWTIME" >> $tmpfile

echo "Info:codfei" >> $tmpfile

echo "" >> $tmpfile;

}

Smail ()

{

Mail-s "$MAIL _sub" $MAILTO < $tmpfile

}

Init

For x in ' df | Grep/dev | awk ' {print $} ' | Sed ' s/%//g '

Todo

If [$x-GT 89]; Then

Mhead;

Df-h >> $tmpfile;

Smail;

Exit 0;

Fi

Done

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.