Monitordisk. sh:
Copy codeThe Code is as follows :#! /Bin/bash
# Updated: PM By: leif (liangliwen@163.com)
EMAIL =/usr/local/bin/email
/Bin/df-h>/tmp/df.txt
USE = 'df-H | grep-o [0-9] * % | grep-o '[0-9] \ +''
For I in $ USE
Do
If ($ I> 95 ))
Then
$ EAMIL-s "WARNING Low disk space for $ I" liangliwen@163.com break
Fi
If ($ I> 90 ))
Then
$ EMAIL-s "Low disk space for $ I" liangliwen@163.com fi
Done
/Bin/rm-f/tmp/df.txt
To achieve this, any partition uses 90% to send an EMAIL to the specified recipient, and then sends a warning (warning) on the subject of the EMAIL to 95%, indicating that the EMAIL sending program EMAIL is used, is to download the installation from the http://www.cleancode.org/projects/email, more flexible.
Place the shell on crontab as needed to regularly check disk Conditions
The following is a supplement:
Shell script used to monitor disk usage of the remote host. File Name: disklog. shCopy codeThe Code is as follows :#! /Bin/bash
# File name: disklog. sh
# Purpose: monitor the disk usage of a remote system
Logfile = "diskusage. log"
If [[-n $1]
Then
Logfile = $1
If
If [! -E $ logfile]
Then
Printf "%-8 s %-14 s %-9 s %-8 s %-6 s %-6 s %-6 s % s \ n" "Date" "IP ADDRESS "" Device "" Capacity "" Used "" Free "" Percent "" Status "> $ logfile
Fi
IP_LIST = "127.0.0.1 0.0.0.0"
# Provide a list of Remote Host IP addresses
(
For ip in $ IP_LIST
Do
Ssh slynux @ $ ip 'df-H' | grep ^/dev/>/tmp/$. df
While read line;
Do
Cur_date = $ (date + % D)
Printf "%-8 s %-14 s" $ cur_date $ ip
Echo $ line | awk '{printf ("%-9 s %-8 s %-6 s %-6 s %-8 s", $1, $2, $3, $4, $5 );}'
Pusg = $ (echo $ line | egrep-o "[0-9] + % ")
Pusg =$ {pusg/\ % /};
If [$ pusg-lt 80];
Then
Echo SAFT
Else
Echo ALERT
Fi
Done </tmp/$. df
Done
) >>> $ Logfile
We can use cron to schedule script execution at a fixed interval. For example, we can add such entries to the crontab to automatically run the script at ten o'clock A.M. every day:
00 10 ***/home/sh/disklog. sh/home/log/diskusg. log
Run the crontab-e command to add and save the preceding line.
You can also manually execute:
$./Disklog. sh