Automatic operation and Maintenance Program 1: Batch self-test, update, configuration modification, release

Source: Internet
Author: User
Tags rsync

#!/bin/baship_list= (192.168.1.100192.168.1.101192.168.1.102192.168.1.103192.168.1.104) #new  server  ipcmd_list= (check running state firewall off off Game Program update Service end opener add Whitelist Open firewall) Cat /dev/null > tmp.logfunction check _status () {  touch 3.log  for ip in ${ip_list[@]}  do     nc -z -v -w 1  $ip  8000 >> 3.log   done  num=$ (cat 3.log | grep succeeded | wc -l)   echo   "Server altogether  ${#IP_LIST [@]}  console is on   $num   shutdown status is  $ ((${#IP_LIST [@]}-$num)   Taiwan     "  rm -rf 3.log}function mulu () {  sep=": "  i=0   while  (( i < ${#CMD_LIST [@]} ));d o    echo  "$ ((i+1)) $sep $ {cmd_list[$i]} "    let " i= (i+1) "  done  echo -e  " \033[31;1mall: Perform the above operation in turnFor M: View operation directory Q: Exit program ===================================\033[;0m "}echo -e  " \033[31;1m====  This program is used to perform the following operations in bulk  ====\033[;0m "mulucmd=" "flag=1while [[  $flag  == 1 ];d o   if [[ -z  $n  ]] | |  [[  $n  == 0 ]];then    read -p  Please enter the operation code to be executed (M View menu):   " n  fi  if [[ $ (seq ${#CMD_LIST [@]})  =~  $n  ]]   then    echo ;    echo -e -n  ">> > The operation being performed is: \033[33;1m${cmd_list[$ ((n-1))]}\033[;0m, "    read -p " confirmation start? (yes/no)  c     #echo   >>> The action being performed is: ${cmd_list[$ ((n-1))}, do you want to confirm the start? (yes/no) "    if [[  $c  == " y " ]] | |  [[  $c  ==  "yes"  ]]; then           case  $n  IN&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;1):                 check_status;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;2):                 cmd= "/sbin/iptables-restore /etc/ Sysconfig/iptables.killrule "                 ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;3):                 cmd= "Control stop";; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;4):                 /root/ios/rsyncUpdate.sh                 ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;5):                 cmd= "Control start";; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;6):                 read -p  "Please enter the IP you want to Whitelist:"  bip                 cmd= "/sbin/ iptables -i input 2 -s  $bip  -j accept "                 ;; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;7):                 cmd= "/sbin/iptables-restore /etc/ Sysconfig/iptables.startrule ";;           esac          for ip in ${ip_list[@]}           do             if [ ! -z  "$cmd"  ]; then               salt  $ip  cmd.run  "$cmd"  | tee -a  tmp.log 2>&1                #echo   $cmd                   #echo   "salt  $ip  cmd.run  ' $cmd '  | tee -a admin.log"   >> 2.log                  #echo   $cmd                   #echo   $ip              #else                 #pass              fi          done         fi        if [ $? == 0  ]; then          echo  "Execution Success"          else          echo  "Execution error, error id:$?"         fi    read -p  "Please enter the operation code to be executed:   " n    continue  else    case  $n  inm):   mulu  let  "n=0"   let  "flag=1";; Q):  break;; All):   echo  "^^ ^^ ^  is about to begin the sequence above   ^^ ^^ ^" for ip in ${ip_list[@]}do  echo  "> >>>>  in action: $ip  <<<<<   salt  $ip  cmd.run  ' Iptables-restore /etc/sysconfig/iptables.killrule ' echo  "Firewall is off" sleep 1  salt  $ip  cmd.run  ' control stop ' echo  ' program is off ' sleep 1  rsync -vacb -- backup-dir=/db_backup/$BACKUP _dir --progress --exclude-from=/root/exclude.list --password-file= /etc/rsyncd.secrets /home/game/wh [email protected] $ip::wh/  salt  $ip   cmd.run  '/home/game/wh.sh ' echo  "Server has been updated" #sleep  1  salt  $ip  cmd.run  ' Control start ' echo  ' program has been opened, GM open the test "sleep 1done  break;; *):  read -p  "input error, please re-enter:"  n  let  "flag=1";;     esac  fidoneecho  "OK"

# #本程序使用到的工具有nc, Saltstack,rsync

This article is from a "sense of direction" blog, be sure to keep this source http://itech.blog.51cto.com/192113/1745942

Automatic operation and Maintenance Program 1: Batch self-test, update, configuration modification, release

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.