5 #@Created: 2011-01-22-15:20
7 PATH
=/bin
:/usr
/bin
:/usr
/local
/bin
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"
34 echo "$PROGRAM version $VERSION"
40 EXITCODE
=$
((EXITCODE
+ 1))
41 #EXITCODE=`expr $EXITCODE + 1`
48 HOMEPROXY
=192.168.67.245
49 SECONDPROXY
=192.168.72.103
56 if [[ $hostname = "football12" ]]
91 error
"Unrecognized option: $1"
100 #----------- end of phrase argument ---------------#
102 # make tunnel from local to destination by ssh server
104 # $2 remote host name
107 # $5 record string for sed
110 echo -e "\nconnect from local port $1 to $4 for $2:$3 ..."
111 if grep -q $5 $HOME/tunnel.list
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$
116 echo -e "\talready connected, ignore $5"
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
137 if [ $athome = "yes" ]
139 echo "nothing for $2:$3 now"
140 #mt $1 $SECONDPROXY $1 $HOMEPROXY "$2:$3"
142 mt
$1 $2 $3 $QAPROXY "$2:$3"
149 cat $HOME/tunnel.list |
while read line
151 if ps
-ef|
grep " `echo $line|cut -d " " -f2`" |
grep -q ssh$
156 #echo $line |cut -d " " -f1
161 if [ $option = "list" ]
167 if [ $# -eq 0 -a $all != "yes" ]
175 echo "use all setting, means connet to qasox02, qapc27 qapc42 qapc45 qapc59 and others ..."
176 tunnel
="qasox02 qapc27 qapc42 qapc45 qapc59 others"
178 echo "connet to $* ..."
186 maketunnel
10002 "qasox02.grid.datasynapse.com" 22
189 maketunnel
10006 "qasox06.grid.datasynapse.com" 22
192 maketunnel
10051 "qa51.grid.datasynapse.com" 22
195 maketunnel
9942 "qapc42.grid.datasynapse.com" 3389
198 maketunnel
9242 "qapc42.grid.datasynapse.com" 22
201 maketunnel
9945 "qapc45.grid.datasynapse.com" 3389
204 maketunnel
9927 "qapc27.grid.datasynapse.com" 3389
207 maketunnel
9259 "qapc59.grid.datasynapse.com" 22
210 maketunnel
9959 "qapc59.grid.datasynapse.com" 3389
213 mt
20058 "192.168.67.243" 3389 $THIRDPROXY "192.168.67.243:3389"
216 mt
22058 "192.168.67.243" 22 $THIRDPROXY "192.168.67.243:22"
219 mt
20098 "192.168.67.242" 3389 $THIRDPROXY "192.168.67.242:3389"
222 mt
22098 "192.168.67.242" 443 $THIRDPROXY "192.168.67.242:443"
225 mt
30103 "192.168.72.103" 3389 $HOMEPROXY "192.168.72.103:3389"
228 mt
32103 "192.168.72.103" 22 $HOMEPROXY "192.168.72.103:22"
231 if [ $athome = "yes" ]
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"
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