-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmgo.sh
executable file
·92 lines (85 loc) · 1.65 KB
/
mgo.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
usage() {
echo
echo "Usage: mgo.sh [-r] [-d] [-h]"
echo
echo "-r - Get your depolyment server by the name of application."
echo "-d - Go to the depolyment server directly by the number of server list."
echo "-h - This help text."
echo
}
load_relay() {
while read line
do
eval $line
done < $1/relay.config
}
load_dest() {
if [ ! -f "$1/$2.config" ]; then
echo "Please check your $1/$2.config..."
exit 1
fi
unset dest
k=0;
while read line
do
dest[k++]=$line
done < $1/$2.config
}
path=`dirname $0`
load_relay $path
load_dest $path "dest"
PS3="MgO is short for Meituan Go... =====> "
while getopts "r:d:h" arg
do
case $arg in
r)
load_dest $path $OPTARG
;;
d)
n=`echo $OPTARG | grep "[^0-9]"`
if [ -n "$n" ]; then
echo "Please enter a number as param..."
exit 1
fi
if [[ "(($OPTARG-1))" -ge "${#dest[*]}" ]]; then
echo "Please enter a number which is in the range of destation array as param..."
exit 1
fi
direct=`echo ${dest[(($OPTARG-1))]} | sed 's/\[.*\]//g'`
if [[ "$direct" == "relay.sankuai.com" ]]; then
ssh $host
else
ssh -t $host ssh $direct
fi
exit 0
;;
h)
usage
exit 0
;;
?)
echo "ERROR: Unknow option..."
usage
exit 1
;;
esac
done
select selected in ${dest[@]};
do
d=`echo ${selected} | sed 's/\[.*\]//g'`
echo "\033[32mlogin to ${selected}\033[0m"
case $d in
relay.sankuai.com)
ssh $host
break
;;
$d)
ssh -t $host ssh $d
break
;;
*) echo "There is someting wrong with your enter."
;;
esac
done