Any partition used to 90% send a message to the specified recipient, to 95% on the subject of the message Warning (warning), instructions to send mail program email
#!/bin/bash
#Updated: 2008-03-03 PM by:leif ([email protected])
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" [e-mail protected] Break
Fi
if (($i > 90))
Then
$EMAIL-S "Low disk space for $i" [EMAIL protected] fi
Done
/bin/rm-f/tmp/df.txt
To achieve the purpose, any one partition uses 90% to send a message to the specified recipient, to 95% on the subject of the message Warning (warning), stating that the email program email is from Http://www.cleancode.org/projects/email Download and install, more flexible.
Put the shell on the crontab as needed to implement a timed check of the disk
The following are additional content:
Shell script for monitoring remote host disk usage, file name: disklog.sh
#!/bin/bash
# File Name: disklog.sh
# Purpose: Monitor disk usage for remote systems
Logfile= "Diskusage.log"
if [[-N $]]
Then
Logfile=$1
If
if [!-e $logfile]
Then
printf "%-8s%-14s%-9s%-8s%-6s%-6s%-6s%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 [email protected] $ip ' df-h ' | grep ^/dev/>/TMP/$$.DF
while read line;
Do
cur_date=$ (Date +%d)
printf "%-8s%-14s" $cur _date $ip
echo $line | awk ' {printf ("%-9s%-8s%-6s%-6s%-8s", $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 regular intervals, such as by adding such entries in crontab to run the script automatically 10 o'clock in the morning every day:
XX * * */home/sh/disklog.sh/home/log/diskusg.log
Execute the CRONTAB-E command, add the above line and save.
You can also do this manually:
$./disklog.sh
Shell script to monitor disk usage (local + remote)