-
Notifications
You must be signed in to change notification settings - Fork 11
/
exec.sh
executable file
·63 lines (54 loc) · 1.69 KB
/
exec.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# ---------------------------------------------------------------
# 多服务器命令批量执行脚本
#
# Filename: exec.sh
# Copyright: (c) 2016 360 Free WiFi Team. (http:://wifi.360.cn)
# License: http://www.apache.org/licenses/LICENSE-2.0
# ---------------------------------------------------------------
FILENAME=$0
# load function
DEPLOY_DIRECTORY=`dirname $FILENAME`
. $DEPLOY_DIRECTORY/function.sh
. $DEPLOY_DIRECTORY/cecho.sh
. $DEPLOY_DIRECTORY/conf.sh
. $DEPLOY_DIRECTORY/init.sh
# 使用帮助
if [ $# -lt 1 ] || [ "-h" = "$1" ] || [ "--help" = "$1" ]; then
showHelpByExec
fi
if [ $# == 2 ] &&[ "$2" == "debug" ]; then
# 确认服务器列表
cecho -n "============== 服务器列表(开始) ==============" -n
no=0;
for host in $EXEC_HOSTS
do
no=`echo "$no + 1" | bc`
cecho $no". " -c "$host"
INT_COUNT_SUCCESS=$((INT_COUNT_SUCCESS + 1))
done
cecho -n "============== 服务器列表(结束) ==============" -n
fi
confirm "确认服务器列表?"
# $? 上一个命令的退出码
if [ 1 != $? ]; then
if [ $# == 2 ] &&[ "$2" == "debug" ]; then
cecho -n "[" -p "result" -w "] 机器数量: " -g $INT_COUNT_SUCCESS -p " 放弃了本次操作!" -n
fi
exit 0;
fi
INT_COUNT_SUCCESS=0;
# 开始批处理执行命令
for host in $EXEC_HOSTS
do
if [ $# == 2 ] &&[ "$2" == "debug" ]; then
INT_COUNT_SUCCESS=$((INT_COUNT_SUCCESS + 1))
cecho -n -w $INT_COUNT_SUCCESS". [ " -c "$host" -w " ]" -n
$SSH $host "$1"
else
$SSH $host "$1"
fi
done
if [ $# == 2 ] &&[ "$2" == "debug" ]; then
cecho -n -g "[" -g "result" -w "] 机器数量: " -g $INT_COUNT_SUCCESS -w " Done!" -n
fi