"Shell combat" executes commands on multiple servers in bulk

Source: Internet
Author: User

Function Description: Execute commands on multiple servers in bulk

1 #!/bin/bash2 3 # ==========================================4 #function: Execute commands on multiple servers in bulk5 #method:./batch_cmd_manager.sh <cmd_to_exec>6 #return: List of results returned by each server execution command7 #Prerequisite: A password-free login is set up on each server where the command is to be executed8 #warning: Prohibit execution of commands such as deletion, formatting, etc. that may cause serious consequences9 #Date: 2018-04-23Ten #By:hackhan One #Other: Set up a password-free login reference: 51902208 A #Files: batch_cmd_manager.sh - # ========================================== -  the  - Do_command () - { -Hosts= ' Sed-n'/^[^#]/p'Hostlist.txt ' +          forHostinch$hosts -  Do +Echo"" A Echo HOST $host atSSH $host"[email protected]" -  Done -         return0 - } -  -  in if[ $#! = 1] -  Then toEcho"==========================================" +Echo"function: Execute commands on multiple servers in bulk" -Echo"method: "<cmd_to_exec>\"" theEcho"return: List of results returned by each server execution command" *Echo"Prerequisite: A password-free login is set up on each server where the command is to be executed" $Echo"warning: Prohibit execution of commands such as deletion, formatting, etc. that may cause serious consequences"Panax NotoginsengEcho"==========================================" -Exit 1 the fi +  A  theEcho"Are you sure you want to execute the command? [Yes/no]:[email protected]" + Read To_run -  $local_ip=10.143.2.4 $  - if[$to _run ="Yes"-O $to _run ="YES"-O $to _run ="y"-O $to _run ="Y" ] -  Then theEcho"" -Echo-e"\033[31m Execution command: [email protected] \033[0m"WuyiDo_command"[email protected]" theEcho"" - echo HOST $local _ip Wu [email protected] - Else AboutEcho"cancel the execution of the command! " $ fi -  -Echo"" -Echo"=========================================="

Save the IP Address list file Hostlist.txt:

# List of IP addresses, one per line xx.xx.xx.xxxx.xx.xx.xxxxxx.xxx.xx.xx

"Shell combat" executes commands on multiple servers in bulk

Related Article

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.