Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Operation and maintenance Monitoring script by Bash Shell

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how Bash Shell implements the monitoring script for operation and maintenance. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

First, functional analysis

1. The easiest way to know whether the server is connected to the public network is to ping the IP address of a public network.

two。 If you ping the IP address of a public network, there is a single point of failure. If the IP is down, it is not the reason for the server, so two IP should be selected here.

3. Here we choose google.cn and baidu.com, the possibility of hanging them together is almost zero, this security level is acceptable to us.

4. How can you let me know if you find that the Internet is not available (that is, Baidu and Google are both ping disabled)? Just use the SMS cat to inform me that you just need to insert a row of data into the database.

Second, the conception of the realization of code function

1.ping Baidu, record the execution result in a temporary file. The return value of ping is 0 and the return value of ping is 1.

2.ping Google, record the results of the execution in a temporary file. The return value of ping is 0 and the return value of ping is 1.

3. Give the two return values of the above two commands to a variable.

4. Determine the value of this variable. 00 is connected, 01 or 10 does not represent a problem with the server. If it is 11, it must be that the server and the external network are down.

5. It's time to call the police to SA.

III. Code implementation

#! / bin/bash

#-Network Check And Send a Message BY monitor Zhao-

DOMAIN1=www.baidu.com

DOMAIN2=www.google.cn

USER=sms

PASSWORD=unixhot

MYSQLHOST=192.168.0.12

Ping-c 2 $DOMAIN1 > / dev/null

Echo-n $? > / tmp/network-status

Ping-c 2 $DOMAIN2 > / dev/null

Echo-n $? > > / tmp/network-status

STATUS= `cat / tmp/network- status`

If ["$STATUS"-eq 11]; then

/ usr/bin/mysql-h $MYSQLHOST-u$USER-p$PASSWORD sms-e "insert into T_SendTask (DestNumber,Content) values"

Fi

Fourth, script execution.

1. Add execution authority, and execute.

two。 Do the network disconnection test manually.

3. Check to see if it is working properly.

4. Apply it to the planned task according to the specific conditions of the production environment.

Thank you for reading! This is the end of the article on "how to implement the operation and maintenance monitoring script in Bash Shell". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report