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