Feature Description:
1, the memory above the set value and sends the mail to the system administrator
2, cup load is too high and send mail to the system administrator
3, never quit monitoring. has been monitoring the background, if there is no processing after a minute to continue to send an email notification
The code is as follows:
memory= ' Free-h | awk ' Nr==3{print $4} ' |cut-c 1-3 '
#取内存现在有值
cup= ' Uptime | awk ' {print $8} ' |sed-n ' s#[^0-9. # #gp ' |cut-c 1 '
#取cup一分钟现有值, go to the integer section.
Caojiaoyue () {
If [$Memory-lt 860];then
echo "Memory alarm, Memory left $memory" | Mail-s "Monitoring Script" [email protected] &>/dev/null
#报警后等待100秒继续 to prevent Full mailbox
Sleep 100
Fi
If [$cup-ge 1];then
echo "Cup load: ${cup} is too high" | Mail-s "Monitoring Script" [email protected] &>/dev/null
Sleep 100
Fi
}
While [1]
Do
Caojiaoyue
Done
#执行方式sh file & can be placed in the background to see the process number through jobs
This article is from "No Lover" blog, please make sure to keep this source http://caojiaoyue.blog.51cto.com/11798573/1922836
Linux mail alarm, monitor memory Cup