-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
76 lines (64 loc) · 2.02 KB
/
utils.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
is_array() {
local array_name="$1"
if [[ "$(declare -p $array_name)" =~ 'declare -a ' ]] || \
[[ "$(declare -p $array_name)" =~ 'typeset -g -a ' ]] || \
[[ "$(declare -p $array_name)" =~ 'typeset -a ' ]] ; then
echo true
else
echo false
fi
}
here=$(cd "$(dirname "${BASH_SOURCE[0]-$0}")"; pwd)
. $here/hosts.sh
# 检查server_set_是否有效
parse_server_set()
{
# echo '$1:' $1
# echo 1
# local server_set_=
# local server_set_
# declare -a server_set_
# unset -a server_set_
eval "server_set_=($1)"
# echo 2
local servers_var="$2"
eval "$servers_var=()"
if ! [ "$(is_array server_set_)" = true ]; then
echo 'invalid server_set_' >&2
echo "Usage: <server_set_name> '<command>'"
echo "Usage: 'server1 server2 server3' '<command>'"
echo "Usage: all 'server1 server2 server{3..5} server{10..13}' '<command>'"
exit
fi
for i in $server_set_; do
if [[ " ${server_sets[@]} " =~ " $i " ]]; then
eval "$servers_var=( \${$servers_var[@]} \${$i[@]} )"
else
eval "$servers_var=( \${$servers_var[@]} $i )"
fi
done
# valid_server=false
# for i in ${server_sets[@]}; do
# if [ "$i" = "$server_set_" ]; then
# valid_server=true
# break
# fi
# done
# if [ "$valid_server" = false ]; then
# # 服务器列表生成
# eval "$servers_var=($server_set_)"
# if ! [ "$(is_array $servers_var)" = true ]; then
# echo 'invalid server_set_' >&2
# echo "Usage: <server_set_name> '<command>'"
# echo "Usage: 'server1 server2 server3' '<command>'"
# echo "Usage: all 'server1 server2 server{3..5} server{10..13}' '<command>'"
# exit
# fi
# else
# # 服务器列表生成
# eval "$servers_var=(\${$server_set_[@]})"
# fi
unset server_set_
}
alias monitor_file="\vim -u ${admin_tool_path}/monitor_file.vim"