myssh: Allow override for target port
This commit is contained in:
parent
f6e126dfcc
commit
8a896cda42
1 changed files with 6 additions and 4 deletions
10
script/myssh
10
script/myssh
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
[ -z $SQL_PROXY_HOST ] && SQL_PROXY_HOST="localhost"
|
[ -z $SQL_PROXY_HOST ] && SQL_PROXY_HOST="localhost"
|
||||||
|
[ -z $SQL_PROXY_DB_PORT ] && SQL_PROXY_DB_PORT="3306"
|
||||||
CONNECTION_CACHE="$HOME/.cache/sqlproxy_$SQL_PROXY_HOST"
|
CONNECTION_CACHE="$HOME/.cache/sqlproxy_$SQL_PROXY_HOST"
|
||||||
|
|
||||||
HELP="Usage: myssh [ls|connect]\n
|
HELP="Usage: myssh [ls|connect]\n
|
||||||
|
@ -36,15 +37,16 @@ disconnect() {
|
||||||
|
|
||||||
port_forward() {
|
port_forward() {
|
||||||
ACTIVE_HOST=$(cat $CONNECTION_CACHE)
|
ACTIVE_HOST=$(cat $CONNECTION_CACHE)
|
||||||
if [ -z $ACTIVE_HOST ] || [ $ACTIVE_HOST != $1 ]
|
if [ -z $ACTIVE_HOST ] || [ $ACTIVE_HOST != $1:$SQL_PROXY_DB_PORT ]
|
||||||
then
|
then
|
||||||
|
echo "Reconnect"
|
||||||
if [ ! -z $ACTIVE_HOST ]
|
if [ ! -z $ACTIVE_HOST ]
|
||||||
then
|
then
|
||||||
ssh -O cancel -L 3306:$ACTIVE_HOST:3306 -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST q
|
ssh -O cancel -L 3306:$ACTIVE_HOST -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST q
|
||||||
fi
|
fi
|
||||||
ssh -O forward -L 3306:$1:3306 -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST
|
ssh -O forward -L 3306:$1:$SQL_PROXY_DB_PORT -S $HOME/.ssh/controlmasters/%r@%h:%p $SQL_PROXY_HOST
|
||||||
fi
|
fi
|
||||||
echo $1 > $CONNECTION_CACHE
|
echo $1:$SQL_PROXY_DB_PORT > $CONNECTION_CACHE
|
||||||
}
|
}
|
||||||
|
|
||||||
ls_hosts() {
|
ls_hosts() {
|
||||||
|
|
Loading…
Reference in a new issue