Shell script Monitoring Server online status and message alerting method _linux Shell

Source: Internet
Author: User
Tags sleep

For the server, the online rate is very important, there are problems to be resolved in a timely manner, but the system administrator can not be kept in the computer next to the site through the script to monitor the problem in a timely manner through mail notify the administrator, if it is 139 mailbox can also be free mobile phone SMS notification.
Note: Sending mail directly through the system is easy to intercept, and you can use mail to connect to a third party SMTP to send mail.

Shell Script Implementation code:

Copy Code code as follows:

#!/bin/bash
#set-X
While True
Todo
list= (www.jb51.net s.jb51.net)
Mail=jmj@jb51.net
date=$ (date-d "Today" + "%y-%m-%d-%h:%m:%s")
I=0
id=${#list [*]}
While [$i-lt $id]
Todo
If Ping-c1 ${list[$i]} >/dev/null
Then
echo $date: Server ${list[$i]} can ping.
Else
If Curl-m ${list[$i]} >/dev/null
Then
echo $date: Server ${list[$i]} Ping is not available to open the Web page.
Else
echo "Hello, according to system monitoring Server ${list[$i]} can not access and ping impassability, please deal with!" Failure occurred: $date "|mail-s" Server ${list[$i]} cannot connect! Failure occurred: $date "$mail
Until
date=$ (date-d "Today" + "%y-%m-%d-%h:%m:%s")
PING-C1 ${list[$i]} >/dev/null && echo "Congratulations! Server ${list[$i]} has returned to normal, recovery time: $date "|mail-s" Server ${list[$i]} has returned to normal! Recovery time: $date "$mail
Todo
Sleep 5
Done
Fi
Fi
Let i++
Done
Sleep 60
Done

Related Article

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.