change to 67.24x
[hombase.git] / other-sh / mt.sh
blobfda2cfd28a76d58586c54bc0becf52919108fb1a
1 #!/bin/sh
3 #mt.sh-- _describe_
4 #@Author: LiFan
5 #@Created: 2011-01-22-15:20
7 PATH=/bin:/usr/bin:/usr/local/bin
9 error()
11 echo "$@" 1>&2
12 usage_and_exit 1
15 usage()
17 echo "Usage: $PROGRAM [--list] [--all|-a] [--athome|-m] [--proxy|-x] [--prox-home|-xh] [--help] [--version] [host-name]"
18 echo -e "for example:"
19 echo -e "\tmt.sh --list"
20 echo -e "\tmt.sh qapc27"
21 echo -e "\tmt.sh -x 192.168.79.xx tu98"
22 echo -e "\tmt.sh x103-22"
23 echo -e "\tmt.sh -xh 192.168.67.245 others"
26 usage_and_exit()
28 usage
29 exit $1
32 version()
34 echo "$PROGRAM version $VERSION"
37 warning()
39 echo "$@" 1>&2
40 EXITCODE=$((EXITCODE + 1))
41 #EXITCODE=`expr $EXITCODE + 1`
45 EXITCODE=0
46 PROGRAM=`basename $0`
47 VERSION=1.0
48 HOMEPROXY=192.168.67.245
49 SECONDPROXY=192.168.72.103
50 THIRDPROXY=
51 QAPROXY=qaproxy
52 all=no
53 athome=no
55 hostname=`hostname`
56 if [[ $hostname = "football12" ]]
57 then
58 athome=yes
61 option=conn
63 while test $# -gt 0
65 case $1 in
66 --all | -a)
67 all=yes
69 --help | -h)
70 usage_and_exit 0
72 --version | -v)
73 version
74 exit 0
76 --list | -l)
77 option=list
79 --athome| -m)
80 athome=yes
82 --proxy| -x)
83 shift
84 THIRDPROXY=$1
86 --proxy-home| -xh)
87 shift
88 HOMEPROXY=$1
90 -*)
91 error "Unrecognized option: $1"
94 break
96 esac
97 shift
98 done
100 #----------- end of phrase argument ---------------#
102 # make tunnel from local to destination by ssh server
103 # $1 local port
104 # $2 remote host name
105 # $3 remote port
106 # $4 sshd server
107 # $5 record string for sed
108 mt()
110 echo -e "\nconnect from local port $1 to $4 for $2:$3 ..."
111 if grep -q $5 $HOME/tunnel.list
112 then
113 echo -e "\tyes, $5 in tunnel.list"
114 if test -n "`grep $5 $HOME/tunnel.list|cut -d " " -f2`" && ps -ef|grep " `grep $5 $HOME/tunnel.list|cut -d " " -f2`" |grep -q ssh$
115 then
116 echo -e "\talready connected, ignore $5"
117 return
119 else
120 echo -e "\tno, $5 not in tunnel.list, add it"
121 echo $5 $pid >> $HOME/tunnel.list
124 ssh -N -f -L *:$1:$2:$3 $4
125 pid=`ps -ef|grep ssh$|tail -1|awk '{print $2}'`
127 echo -e "\t$2:$3 $pid"
128 sed -e "s/$5.*$/$5 $pid/g" $HOME/tunnel.list -i
133 # make tunnel from local to destination by ssh server
134 # $1:local port $2:remote host name $3:remote port
135 maketunnel()
137 if [ $athome = "yes" ]
138 then
139 echo "nothing for $2:$3 now"
140 #mt $1 $SECONDPROXY $1 $HOMEPROXY "$2:$3"
141 else
142 mt $1 $2 $3 $QAPROXY "$2:$3"
147 listtunnel()
149 cat $HOME/tunnel.list | while read line
151 if ps -ef|grep " `echo $line|cut -d " " -f2`" |grep -q ssh$
152 then
153 echo $line
154 else
156 #echo $line |cut -d " " -f1
158 done
161 if [ $option = "list" ]
162 then
163 listtunnel
164 exit 0
167 if [ $# -eq 0 -a $all != "yes" ]
168 then
169 usage_and_exit 0
173 if [ $all = "yes" ]
174 then
175 echo "use all setting, means connet to qasox02, qapc27 qapc42 qapc45 qapc59 and others ..."
176 tunnel="qasox02 qapc27 qapc42 qapc45 qapc59 others"
177 else
178 echo "connet to $* ..."
179 tunnel=$*
182 for i in $tunnel
184 case $i in
185 qasox02)
186 maketunnel 10002 "qasox02.grid.datasynapse.com" 22
188 qasox06)
189 maketunnel 10006 "qasox06.grid.datasynapse.com" 22
191 qa51)
192 maketunnel 10051 "qa51.grid.datasynapse.com" 22
194 qapc42)
195 maketunnel 9942 "qapc42.grid.datasynapse.com" 3389
197 qapc42-22)
198 maketunnel 9242 "qapc42.grid.datasynapse.com" 22
200 qapc45)
201 maketunnel 9945 "qapc45.grid.datasynapse.com" 3389
203 qapc27)
204 maketunnel 9927 "qapc27.grid.datasynapse.com" 3389
206 qapc59-22)
207 maketunnel 9259 "qapc59.grid.datasynapse.com" 22
209 qapc59)
210 maketunnel 9959 "qapc59.grid.datasynapse.com" 3389
212 tu12)
213 mt 20058 "192.168.67.243" 3389 $THIRDPROXY "192.168.67.243:3389"
215 tu12-22)
216 mt 22058 "192.168.67.243" 22 $THIRDPROXY "192.168.67.243:22"
218 tuc2)
219 mt 20098 "192.168.67.242" 3389 $THIRDPROXY "192.168.67.242:3389"
221 tuc2-22)
222 mt 22098 "192.168.67.242" 443 $THIRDPROXY "192.168.67.242:443"
224 x103)
225 mt 30103 "192.168.72.103" 3389 $HOMEPROXY "192.168.72.103:3389"
227 x103-22)
228 mt 32103 "192.168.72.103" 22 $HOMEPROXY "192.168.72.103:22"
230 others)
231 if [ $athome = "yes" ]
232 then
233 mt 30195 192.168.67.195 3389 $HOMEPROXY "192.168.67.195:3389"
234 mt 32195 192.168.67.195 22 $HOMEPROXY "192.168.67.195:22"
235 else
236 #maketunnel 9965 "qapc65.grid.datasynapse.com" 3389
237 #maketunnel 9968 "qapc68.grid.datasynapse.com" 3389
238 #maketunnel 9970 "qapc70.grid.datasynapse.com" 3389
239 #maketunnel 9973 "qapc73.grid.datasynapse.com" 3389
240 #maketunnel 9978 "qapc78.grid.datasynapse.com" 3389
241 maketunnel 9907 "qapcx07.grid.datasynapse.com" 3389
242 maketunnel 9966 "qapc66.grid.datasynapse.com" 3389
245 esac
246 done