Monitordisk.sh is as follows
Copy Code code as follows:
#!/bin/bash
#Updated: 2008-03-03 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
Todo
if (($i > 95))
Then
$EAMIL-S "WARNING low disk spaces for $i" liangliwen@163.com break
Fi
if (($i > 90))
Then
$EMAIL-S "low disk spaces for $i" liangliwen@163.com fi
Done
/bin/rm-f/tmp/df.txt
To achieve the purpose, any one partition using to 90% to send a message to the designated recipient, to 95% on the subject of the message Warning (warning), instructions to send mail program email, is from Http://www.cleancode.org/projects/email Download and install, more flexible.
Put this shell on crontab to implement a timed check of the disk
The following are supplementary content:
Shell script for monitoring remote host disk usage, filename: disklog.sh
Copy Code code as follows:
#!/bin/bash
# FileName: disklog.sh
# Purpose: Monitoring the disk usage of 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
Todo
SSH slynux@ $ip ' df-h ' | grep ^/dev/>/TMP/$$.DF
while read line;
Todo
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 a fixed interval, such as adding such an entry in crontab to enable the script to run automatically 10 o'clock in the morning every day:
* * */home/sh/disklog.sh/home/log/diskusg.log
Execute the CRONTAB-E command, add the line above and save it.
can also be performed manually:
$./disklog.sh