标签:http 其他 xxx https span 执行命令 取消 read details
功能说明:批量在多台服务器上执行命令
1 #!/bin/bash 2 3 # ========================================== 4 # 功能:批量在多台服务器上执行命令 5 # 方法:./batch_cmd_manager.sh <cmd_to_exec> 6 # 返回:各服务器执行命令返回的结果列表 7 # 前提:在待执行命令的各个服务器上设置了免密登录 8 # 警告:禁止执行删除、格式化等这样的可能造成严重后果的命令 9 # 日期:2018-04-23 10 # By:HackHan 11 # 其他:设置免密登录参考:https://blog.csdn.net/zoombinde/article/details/51902208 12 # 文件:batch_cmd_manager.sh 13 # ========================================== 14 15 16 do_command() 17 { 18 hosts=`sed -n ‘/^[^#]/p‘ hostlist.txt` 19 for host in $hosts 20 do 21 echo "" 22 echo HOST $host 23 ssh $host "$@" 24 done 25 return 0 26 } 27 28 29 if [ $# != 1 ] 30 then 31 echo "==========================================" 32 echo "功能:批量在多台服务器上执行命令" 33 echo "方法:$0 \"<cmd_to_exec>\"" 34 echo "返回:各服务器执行命令返回的结果列表" 35 echo "前提:在待执行命令的各个服务器上设置了免密登录" 36 echo "警告:禁止执行删除、格式化等这样的可能造成严重后果的命令" 37 echo "==========================================" 38 exit 1 39 fi 40 41 42 echo "确定要执行命令?[yes/no]:$@ " 43 read to_run 44 45 local_ip=10.143.2.4 46 47 if [ $to_run = "yes" -o $to_run = "YES" -o $to_run = "y" -o $to_run = "Y" ] 48 then 49 echo "" 50 echo -e "\033[31m执行命令 : $@ \033[0m" 51 do_command "$@" 52 echo "" 53 echo HOST $local_ip 54 $@ 55 else 56 echo "取消执行命令!" 57 fi 58 59 echo "" 60 echo "=========================================="
保存IP地址列表的文件hostlist.txt:
# IP地址列表,每行一个 xx.xx.xx.xx xx.xx.xx.xxx xxx.xxx.xx.xx
标签:http 其他 xxx https span 执行命令 取消 read details
原文地址:https://www.cnblogs.com/leejack/p/8927166.html