Shell script for automatic inspection of multiple servers

Source: Internet
Author: User
Tags egrep

Shell script for automatic inspection of multiple servers Abstract: O & M services for more than 20 (or more) servers in a project, the performance inspection of servers is performed every day to check whether the CPU, memory, and disk space of the servers are within the normal range. In this way, we do the same repetitive work every day or every fixed period of time. To simplify repetitive work, I wrote an automatic inspection script based on the liunx server, in crontab, set a fixed time for automatic execution to reduce manual repetitive work. Environment: the main servers in my project are LINUX and AIX, with a total of about 30 servers. The current workload is inspection twice a week. You can manually log on to each server and use the corresponding commands to view the server performance parameters. Idea: 1. the networks of all servers are in the same LAN, and all networks are interconnected. 2. Select a server with relatively good performance or less running pressure on the server as the inspection server. 3. This server is used to inspect other servers, and then the inspection results are recorded on the inspection server. 4. The inspection results of each server are named by time and ip address, and all inspection results are compressed and packaged. 5. Each maintenance personnel only needs to obtain the compressed package regularly to view the final result, eliminating the need to log on to and enter the same command to view each server. Specific implementation Script :#! /Bin/bashecho "start running! "| Tee-a LANG = enset 'date' path ="/home/check "echo" start running! "| Tee-a $ path/log/$1-$2-$3. logif [-d/home/check/result/$1-$2-$3]; then echo ''elsemkdir/home/check/result/$1-$2-$3 echo 'date + "% Y/% m/% d-% H: % M: % S "'" create "" $1-$2-$3 "" directory success! "| Tee-a $ path/log/$1-$2-$3. logfiecho 'date + "% Y/% m/% d-% H: % M: % S" '"starting reading linuxconfig.txt! "| Tee-a $ path/log/$1-$2-$3. logcat "$ path"/config/linuxconfig.txt | while read line; doip = '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 sleep 1 echo password sleep 3 echo" free-k "echo" "echo" df -k "echo" "# memory_used_rateecho" ps-ef | grep java "echo" "echo" netstat-an | egrep-n' 8010 | 8008 | 9008 | 44444 | 4100 '" echo "" echo "ifconfig-a" echo "" echo "top-n1 | sed-n' 1, 5 p '"echo" exit "sleep 5) | telnet $ ip>/home/check/result/$1-$2-$3/$ip-00001-00002-00003-00004.txt echo 'date + "% Y/% m/% d-% H: % M: % S "'" chec K LINUX "$ ip" end! "| Tee-a $ path/log/$1-$2-$3. logecho "" | tee-a $ path/log/$1-$2-$3. logdoneecho '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. logcat "$ path"/config/AIXconfig.txt | while read line; doip = '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 accountsleep 1 echo password sleep 5 echo" "echo" df-k "echo ""# memory_used_rateecho "ps-ef | grep java" echo "" echo "netstat-an | egrep-n' 8010 | 8008 | 9008 | 44444 | 4100 '" echo "" echo "ifconfig- a "echo" "echo" topas "echo" exit "sleep 5) | telnet $ ip>/home/check/result/$1-$2-$3/$ip-00001-00002-00003-00004.txt echo 'date + "% Y/% m/% d-% H: % M: % S "'" check ibm aix "$ ip" end! "| Tee-a $ path/log/$1-$2-$3. logecho "" | tee-a $ path/log/$1-$2-$3. logdoneecho 'date + "% Y/% m/% d-% H: % M: % S" '"end reading AIXconfig.txt! "| Tee-a $ path/log/$1-$2-$3. logzip-r/home/check/result/$1-$2-$3/logs 1-logs 2-logs 3.zip/home/check/result/$1-$2-$3/* echo "End running! "NOTE: The Script inspection is based on the TELNET service, so the checked server must enable the TELNET service, otherwise the inspection will fail.

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.