Server Health status Check script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.