This document 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 checkedyour 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.46has 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.