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