Periodically monitor all server ports, if suspended, send alert messages

Source: Internet
Author: User

function: 1:ping IP address of all in-network machine, if not, send alarm

2: Detect the service port of all machines in the network, if not, send alarm

#!/bin/bash

# #读取IP列表, test a port for IP # #


While Read ip1
Do

Ping-c 2 $ip 1 >>/dev/null 2>&1
If [$?-eq 0]; Then

echo "************************"
echo "Ping $ip 1, OK"

Else
echo "************************"
echo "Ping $ip 1,error,please Check"

Fi


Ipnum= ' echo $ip 1 |awk-f '. ' ' {Print $4} '

ECHO-E---------------------$ipnum

When #ip =238, prot 1521 8089#
When #ip =239, port 8081 80#


Case $ipnum in
238)
For Port1 in 1521 8089
Do
Nc-vv-w1-z $ip 1 $port 1 >>/dev/null 2>&1

If [$?-eq 0];then
echo "$ip 1 $port 1 OK" >>/dev/null 2>&1

Else
echo "$ip 1 $port 1 err,please Check" | Mail-s "Dg-server" [email protected]
Fi
Done
;;
239)
For Port2 in 80 8081
Do
Nc-vv-w1-z $ip 1 $port 2 >>/dev/null 2>&1

If [$?-eq 0];then
echo "$ip 1 $port 2 OK" >>/dev/null

Else
echo "************************"
echo "$ip 1 $port 2 err,please Check"
Fi
Done

;;
Esac

Done<iplist

echo "192.168.16.238\n192.168.16.239" >iplist

Periodically monitor all server ports, if suspended, send alert messages

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.