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

Shell script to realize automatic Inspection of multiple servers-- reference and Learning

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Automatic Inspection of multiple servers based on shell script

Summary:

Operation and maintenance service has more than 20 (or more) servers in a project. The daily performance inspection of the server is to check whether the server's CPU, memory and disk space are within the normal range. Do the same repetitive work every day or every fixed time period like this. In order to simplify the repetitive work, I wrote an automatic inspection script based on liunx server, which can be automatically executed at a fixed time in crontab, so as to reduce the manual repetitive work.

Environment:

The main servers on my project are LINUX and AIX, with a total of about 30 servers. The current workload is to patrol twice a week, manually logging in to each server and using the appropriate commands to view server performance parameters.

Train of thought:

1. All the networks between the servers are in the same local area network, and all the networks are connected to each other.

2. Choose a server with relatively good performance or less running pressure as the patrol server.

3. Through this server to realize the inspection of other servers, and then record the inspection results to the inspection server.

4. The inspection results of each server are distinguished by time and ip. Finally, all the inspection results are compressed and packaged.

5, each time the maintenance personnel only need to pick up the package regularly to check the final result, eliminating the need to log in to each server and enter the same command to view.

#! / bin/bash

Echo "start running" | tee-a

LANG=en

Set `date`

Path= "/ home/check"

Echo "start running" | tee-a $path/log/$1-$2-$3.log

If [- d / home/check/result/$1-$2-$3]

Then

Echo''

Else

Mkdir-p / home/check/result/$1-$2-$3

Echo `date + "% Y/%m/%d-%H:%M:%S" `"create"$1MB / 2MB / 3"directory success" | tee-a $path/log/$1-$2-$3.log

Fi

Echo `date + "% Y/%m/%d-%H:%M:%S" `"starting reading linuxconfig.txt" | tee-a $path/log/$1-$2-$3.log

Cat "$path" / config/linuxconfig.txt | while read line

Do

Ip= `echo $line | cut-d'='- f2`

Echo `date + "% Y/%m/%d-%H:%M:%S" `"check LINUX" $ip "starting" | tee-a $path/log/$1-$2-$3.log

(

Sleep 1

# echo account

Echo root

Sleep 1

# echo password

Echo root

Sleep 3

Echo "free-k"

Echo ""

Echo "df-k"

Echo ""

# memory_used_rate

Echo ""

Echo "netstat-an | egrep-n'80 | 22 | 21 | 23 | 9043 | 9044 | 45331 | 45332 | 39194 | 19195'"

Echo ""

# echo "ifconfig-a"

Echo "/ sbin/ip ad"

Echo ""

Echo "tail-2000 / var/log/messages | grep-v snmp | grep-I error"

Echo ""

Echo "/ bin/dmesg | grep-I error"

Echo ""

Echo "top-N1 | sed-n '1jue 5p'"

Echo "exit"

Echo "/ usr/bin/vmstat 1 3"

Echo ""

Sleep 5

) | telnet $ip > / home/check/result/$1-$2-$3/$ip-$1-$2-$3-$4.txt

Echo `date + "% Y/%m/%d-%H:%M:%S" `"check LINUX" $ip "end" | tee-a $path/log/$1-$2-$3.log

Echo "" | tee-a $path/log/$1-$2-$3.log

Done

Echo `date + "% Y/%m/%d-%H:%M:%S" `"end reading linuxconfig.txt" | tee-a $path/log/$1-$2-$3.log

Echo `date + "% Y/%m/%d-%H:%M:%S" `"starting reading AIXconfig.txt" | tee-a $path/log/$1-$2-$3.log

Cat "$path" / config/AIXconfig.txt | while read line

Do

Ip= `echo $line | cut-d'='- f2`

Echo `date + "% Y/%m/%d-%H:%M:%S" `"check IBM AIX" $ip "starting" | tee-a $path/log/$1-$2-$3.log

(

Sleep 1

# echo account

Echo root

Sleep 1

# echo password

Echo root

Sleep 5

Echo ""

# echo "df-k"

Echo "df-g"

Echo ""

# memory_used_rate

Echo "ps-ef | grep java"

Echo ""

Echo "netstat-an | egrep-n'80 | 22 | 21 | 23 | 9043 | 9044 | 45331 | 45332 | 39194 | 19195'"

Echo ""

Echo "ifconfig-a"

Echo ""

Echo "topas"

Echo "exit"

Sleep 5

) | telnet $ip > / home/check/result/$1-$2-$3/$ip-$1-$2-$3-$4.txt

Echo `date + "% Y/%m/%d-%H:%M:%S" `"check IBM AIX" $ip "end" | tee-a $path/log/$1-$2-$3.log

Echo "" | tee-a $path/log/$1-$2-$3.log

Done

Echo `date + "% Y/%m/%d-%H:%M:%S" `"end reading AIXconfig.txt" | tee-a $path/log/$1-$2-$3.log

Zip-r / home/check/result/$1-$2-$3/$1-$2-$3.zip / home/check/result/$1-$2-$3/*

Echo "End running" Note:

The inspection of the script is based on the TELNET service, so the server being tested must turn on the TELNET service.

Transferred from: http://blog.chinaunix.net/uid-14824714-id-4181103.html

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