This e-mail alert script is widely used. Many of the sendmail and postfix scripts are used, and some of them are used in perl's NET: SMTP and Authen: SASL modules, but I am not using perl well. I always send some inexplicable emails (such as if (a> 1) {print ();}, the last message is 0.99 ......); Finally, the perl program developed by sendEmail sends an alarm, and the real-time monitoring part returns to shell and is finally completed.
Copy codeThe Code is as follows: wget <a href = "http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz"> http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz </a>
Tar zxvf sendEmail-v1.56.tar.gz
Cp sendEmail-v1.56/sendEmail/shell/check/
Cat> check. sh <EOF
File -- check. sh:
Copy codeThe Code is as follows :#! /Bin/bash
Checkmail (){
/Usr/bin/perl./sendEmail-f userid@mail.com-t oneuserid@mail.com-cc twouserid@mail.com threeuserid@mail.com
-U "$ subject"-m "$ data"-s smtp.mail.com-xu userid-xp password
Sleep 300
}
While true; do
Loadavg = 'awk' {print $2} '/proc/loadavg'
Diskuse = 'df | awk'/cache/{print $5 }''
Servrun = 'netstat-pln | awk-F/'/: 80/{print $ NF }''
Ip = 'ifconfig | awk'/cast/{print $2} '| awk-F:' {if (NR = 1) {a = $2} else if (NR = 2) {B = $2} END {print B "-" }''
Data = 'echo-e "ip: $ ip \ nloadavg/5 min: $ loadavg \ tcacheuse %: $ diskuse \ tservice: $ servrun "'
Diskper = 'echo $ diskuse | sed's/% //''
Num = 'ps aux | grep check. sh | grep-v grep | wc-l'
If [[$ num> 2]; then
Break 2
Fi
If [[$ loadavg> 1.00] & [[$ diskper> 90]; then
Subject = "warning-$ ip-loadavg-disk"
Checkmail
Else if [[$ loadavg> 1.00]; then
Subject = "warning-$ ip-loadavg"
Checkmail
Else if [[$ diskper> 90]; then
Subject = "warning-$ ip-disk"
Checkmail
Fi
Sleep 60
Done
EOF
Complete. Execute sh check. sh &>/dev/null.
Alarm Email:
Title: warning-192.168.0.100-10.10.10.10-disk ip: 192.168.0.100-10.10.10.10 loadavg/5 min: 0.38 cacheuse %: 94% service: nginx