Use the Apsara monitoring server to monitor whether the server is online or the service port status is down.

Source: Internet
Author: User
Tags webdate
This document describes how to use shell on a unix host to monitor host survival and port survival. #! /Bin/bash # Authorbyfengzhanhai # Itusedbymonwebserviceandnetandhostliving # Itwascreatedon2012-8-9 # webdate = 'date-d & quot; today & qu this article mainly describes how to use shell on a unix host to monitor host survival and port survival.
#! /Bin/bash
# Author by fengzhanhai
# It used by mon web service and net and host living
# It was created on 2012-8-9
# Webdate = 'date-d "today" + "% Y-% m-% d % H: % M: % S "'
Webdate = 'date-d "today" + "% H: % M: % S "'
# Record the system fault occurrence time point
# Echo $ webdate
Webinfo = "The service's 80 port error! "
Hostinfo = "The mon has been checked your PCserver power off or Disaster"
# Record the fault detected here because I have changed several versions, it is not used for the time being.
Myphone = youphone
Mypwd = yourpassword
# Your flight signal and password
Sendsmsweb (){
Cd/root/mon
For iphone in 'cat smspphone'
Do
# Echo $ iphone
LD_LIBRARY_PATH = ../fetion -- mobile = $ myphone -- pwd = $ mypwd -- to = $ iphone -- msg-utf8 = "$ webinfo $ webdate"> smsp. log
Done

}
# Send a web-based fault alert text message module. The text message module is directly used without reference when called.
Sendsmshost (){
Cd/root/mon
For iphone in 'cat smspphone'
Do
LD_LIBRARY_PATH = ../fetion -- mobile = $ myphone -- pwd = $ mypwd -- to = $ iphone -- msg-utf8 = "$ webinfo $ webdate"> smsp. log
Done

}
# Send host-type fault SMS alert module. Here, I directly apply the message when calling it without reference.
CheckHost (){
Cd/root/mon
For webip in 'cat smspip | awk-F: '{print $1 }''
# Smspip is a text file in the format of 192.168.163.110: 80.
# Use the awk command to go to the first part of its domain, that is, the ip part.
# Of course, you can change the statement to save only ip addresses in the smspip text file.
# In this way, for webip in 'cat smspip' can
Do
Ping-c 1 $ webip>/dev/null 2> & 1
If [$? ! = 0] &! [-F smsp. lock]
# Lock the lock after the alarm is completed to prevent multiple alarms from affecting the engineer's mood
Then
# Sendsmshost
Cd/root/mon
For iphone in 'cat smspphone'
Do
# Touch./smsp. lock
# Echo $ iphone
LD_LIBRARY_PATH = ../fetion -- mobile = $ myphone -- pwd = $ mypwd -- to = $ iphone -- msg-utf8 = "The $ webip can not connect at $ webdate"> smsp. log
Done
Touch./smsp. lock
Fi
Done
}
# The above is the host fault detection module
CheckWeb1 (){
Status = 'telnet 192.168.202.45 80 </dev/null 2>/dev/null | grep '\ ^' | wc-l'
# Because there are only two web servers that need to be tested, there is no need for modularity. # compile your own scripts.
If [$ status! = 1] &! [-F smsp1.lock]
Then
# Sendsmsweb
Cd/root/mon
For iphone in 'cat smspphone'
Do
# Echo $ iphone
LD_LIBRARY_PATH = .. /fetion -- mobile = $ myphone -- pwd = $ mypwd -- to = $ iphone -- msg-utf8 = "The smsp.allook.cn Web Service has been down at $ webdate"> smsp. log
Done
Touch./smsp1.lock
Fi
}
CheckWeb2 (){
Status = 'telnet 192.168.202.46 9001 </dev/null 2>/dev/null | grep '\ ^' | wc-l'
# Because there are only two web servers that need to be tested, you can write your own scripts on the # Line.
If [$ status! = 1] &! [-F smsp2.lock]
Then
# Sendsmsweb
Cd/root/mon
For iphone in 'cat smspphone'
Do
# Echo $ iphone
LD_LIBRARY_PATH = .. /fetion -- mobile = $ myphone -- pwd = $ mypwd -- to = $ iphone -- msg-utf8 = "The sms gw 192.168.202.46 has been down at $ webdate"> smsp. log
Done
Touch./smsp2.lock
Fi
}
# Running the monapp
CheckHost
CheckWeb1
CheckWeb2
After saving and exiting, add it to your crontab in the following format: */5 */root/mon/monwh. sh.
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.