Use the shell implementation to check the memory size, if it is displayed within the set value, send an email alert
Configure Outgoing Mail first
Vi/etc/mail.rc
Add the following information
# for Linux and BSD, this should is Set.set bsdcompatset [email protected] Smtp=smtp.163.comset Smtp-auth-user=alvin smtp- auth-password=123456 Smtp-auth=login
#注意: [email protected] is your e-mail account, Alvin is your mailbox user name, 123456 is your email password
The following is a memory exceeded mailbox Alert script:
[email protected] script]# cat check_memory.sh #!/bin/bashfreemem= ' Free-m|awk ' nr==3 {print $NF} ' chars= ' current Memor Y is $FreeMem. " chars1= "Memory Alert" if [$FreeMem-lt 1800] then echo $CHARS >/tmp/messages.txt mail-s "' Date +%f-% T ' $CHARS 1 "[email protected] </tmp/messages.txtelse echo $CHARSfi
In order to be able to send an email to the police, I set the larger here (1800) The actual production environment settings are not set so large.
To demonstrate this script, you can delete the Echo $CHARS and join the timed task, which executes every 3 minutes.
*/3 * * * */bin/sh/server/script/check_memory.sh &>/dev/null
This article is from the "Knowledge Change Destiny" blog, please be sure to keep this source http://ahtornado.blog.51cto.com/4826737/1930320
Shell implementation checks for memory alarms