In daily work, we regularly check the status of each server, through this shell script system can periodically send the daily server's check results to the mailbox, this script in the formal environment has been running stably.
Because we need to send the detection results by mail, we must first turn on the SendMail service on the server and set it to boot, then we need to set the corresponding parameters in/etc/mail.rc, the parameters in/etc/mail.rc are set as follows:
Set from= Email Address
Address of the Set SMTP=SMTP server
User name for set smtp-auth-user= mailbox
Set smtp-auth-password= password for mailbox
Set Smtp-auth=login Setting the login method
Text ServerList records the server to check in the following format
Server name server IP
The server health check script is as follows:
#!/bin/bash #服务器检查脚本 source /home/jack/.bash_profile #引用普通用户的环境变量 list=/home/jack/shell/monitor/serverlist ip= ' awk ' {print $2} ' $list ' log=/home/jack/shell/monitor/logs/check_$ (date +%f). log subject= "Server Daily Inspection results" if [ '/usr/bin/sudo ls /var/spool/mqueue/|wc -l ' &NBSP;-GE&NBSP;0&NBSP;];THEN&NBSP;&NBSP;&NBSP;SUDO&NBSP;RM&NBSP;-RF /var/spool/mqueue/* fi #清空邮件队列 > $log date|sed ' [email protected]@@g ' >> $log for i in $ip do ping -c 4 $i >/dev/null 2>&1 if [ $? -eq 0 ];then echo "' cat $list |grep $i |awk ' {PRINT&Nbsp;$1} ' normal detection! ' >> $log else echo "' cat $list |grep $i |awk ' { PRINT&NBSP;$1} ' Detection failed! ' >> $log fi done /bin/mail -s $subject < $log [email protected] #邮件发送检测结果
This article is from "My In Lushan" blog, please be sure to keep this source http://147546.blog.51cto.com/137546/1615502
Server Health status Check script