Linux disk space Alert script

Source: Internet
Author: User

1. Must function:

[[email protected] ~]# DF

File system 1k-block already used% mount point available

/dev/mapper/volgroup00-logvol00

11109328 2154636 8381252 21%/

/DEV/SDA1 101086 11999 83868 13%/boot

Tmpfs 1037748 0 1037748 0%/dev/shm

[[email protected] ~]# DF | Sed-n '/\/$/P '

11109328 2154636 8381252 21%/

/$: Represents a line that ends with a slash (/) ($)

[[email protected] ~]# DF | Sed-n '/\/$/p ' | Gawk ' {print $4} '

21%

$4: Indicates a fourth field is printed


[[email protected] ~]# DF | Sed-n '/\/$/p ' | Gawk ' {print $4} ' |sed 's/%//'

21st

S: replace

s/%//: means replacing the percent sign with empty


2. Create a script

Create a script that sends an alert message to Ley users when/when the space exceeds 10%

#!/bin/bash

#monitor Available disk space

s='DF | Sed-n '/\/$/p' | Gawk '{print $4}'|sed 's/%//'

If [$s-ge 10]

Then

echo "$s% userd" | Mail-s "Disk warning" Ley

Fi

~

Ley user must be a user present in the system

******************************************************************************************

[[Email protected] ~]$ Mail view message

Mail version 8.1 6/6/93. Type? For help.

"/var/spool/mail/ley": 5 messages 5 new

>n 1 [email protected] Wed Nov 5 17:02 16/654 "Disk Warning"

N 2 [email protected] Wed Nov 5 17:02 16/654 "Disk Warning"

N 3 [email protected] Wed Nov 5 17:04 16/654 "Disk Warning"

N 4 [email protected] Wed Nov 5 17:04 16/654 "Disk Warning"

N 5 [email protected] Wed Nov 5 17:04 16/654 "Disk Warning"

&

Message 1: The first piece of information

From [email protected] Wed 5 17:02:16 2014

date:wed, 5 Nov 2014 17:02:16 +0800

From:root <[email protected]>

To: [Email protected]

Subject:disk Warning


21% UserD


This article is from the Linux Operations sharing blog, so be sure to keep this source http://liangey.blog.51cto.com/9097868/1572228

Linux disk space Alert script

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.