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 shell monitors scripts

2025-04-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces shell how to monitor the script, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1 prepare the monitoring machine

Linux system, ordinary server is fine, requirements:

Install ssh client, if you want to send SMS, you also need to prepare SMS cat and install gnokii or gammu

2 Edit ssh_config configuration file

/ etc/ssh/ssh_config configuration file, setting "GSSAPIAuthentication no"

Edit / etc/ssh/sshd_config the monitored linux, add UseDNS no, and finally restart sshd

3 Log in to the linux host using the key

4 set up a sh directory to store shell scripts

Mkdir-p / root/sh/crontab/log

The sh directory stores shell scripts

The crontab/log directory stores error messages

5 prepare the configuration file

The code is as follows:

Cat / root/sh/CONFIG

MOBILES= "13xxxxxxxxx 18xxxxxxxxx 13xxxxxxxxx"

MAILS= "dongnan@jb51.net user2@jb51.net"

ESXI_HOSTS= "192.168.57.91 192.168.57.93"

PHYSICAL_HOSTS= "192.168.57.112 192.168.0.1 192.168.57.99"

LINUX_WEB_HOSTS= "192.168.57.82 192.168.57.70 10.0.100.72 10.0.100.73 10.0.100.75 10.0.100.76 10.0.100.77 10.0.100.78"

WIN_WEB_HOSTS= "10.0.100.81 10.0.100.83"

DB_SLAVE_HOSTS= "10.0.100.82"

ALLHOSTS= "$ESXI_HOSTS $PHYSICAL_HOSTS $LINUX_WEB_HOSTS $WIN_WEB_HOSTS $DB_SLAVE_HOSTS"

Note: this profile is used to define global variables, including ip address, email address, phone number, etc.

6 crontab task planning

The code is as follows:

Crontab-l

# ping

* / 1 * / root/sh/chk_ping.sh > > / root/sh/cron.log 2 > & 1

# df

* / root/sh/chk_df.sh > > / root/sh/cron.log 2 > & 1

# load

* / 1 * / root/sh/chk_load.sh > > / root/sh/cron.log 2 > & 1

# mysql_replicate

* / 1 * / root/sh/chk_mysql_replicate.sh > > / root/sh/cron.log 2 > & 1

# web

* / 1 * / root/sh/chk_web.sh > > / root/sh/cron.log 2 > & 1

# xxxx

#..

Note: the execution time of the script] needs to be determined according to the actual function of the script. For example, chk_df monitors the disk space of the server and executes it once an hour.

All monitoring scripts are tested normally under rhel5/centos5, other linux systems please test by yourself.

Thank you for reading this article carefully. I hope the article "how to monitor scripts in shell" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report