Method 1:
Monitoring disk or CPU exceeding a certain value mail alert script:
[email protected] scripts]# cat check.sh
#!/bin/bash
Lang=en_us. UTF-8
cpuused= ' Top-n 1|awk-f ' [,%]+ ' nr==3 {print100-$11} '
diskused=$ (df-h|awk-f ' [%]+ '/\/$/{print $} ')
Logfile=/tmp/jk.log
function Sendmail () {
Mail-s "Monitoring alarm" 1665***[email protected] < $logFile
}
function Check () {
If [' Echo ' $cpuUsed >80 "|BC '-eq 1-o $diskUsed-ge
echo "CPU Usage: ${cpuused}%, disk Usage: ${diskused}%" > $logFile
Sendmail
Fi
}
function Main () {
Check
}
Main
Method 2:
Monitor the disk space size and notify the script by mail:
#!/bin/bash
D= ' Df-h|grep "/dev/sda6" |awk ' {print int ($)} '
Logfile=/tmp/jk.log
function Sendmail () {
Mail-s "Monitoring alarm" 1665***[email protected] < $logFile
}
function Check () {
If
[$d-gt];then
echo "Current hard drive is ${d}%" > $logFile
Sendmail
Else
echo "Hard drive Enough"
Fi
}
function Main () {
Check
}
Main
This article is from the "one small step per day" blog, so be sure to keep this source http://fenyuer.blog.51cto.com/11265169/1917026
Use the shell to write a script that has more than 80% mail alerts on the disk