I need a lot of different aliases to create ssh tunnels to different servers. To give you a few of them:
alias tunnel_1='autossh -M 20000 -N -L 8080:localhost:8080 -N -L 9200:localhost:9200 -N -L 8090:localhost:8090 [email protected]'
alias tunnel_2='autossh -M 20000 -N -L 8000:localhost:8080 -N -L 9200:localhost:9200 -N -L 8090:localhost:8090 [email protected]'
I came up with this function I added in my aliases :
addPort () {
echo "-N -L $1:localhost:$1 "
}
tunnel () {
aliasString="autossh -M 20000 "
for port in "${@:2}"
do
aliasString+=$(addPort $port)
done
aliasString+="$1"
eval $aliasString
}
so I just need to do this to tunnel to the server I want:
tunnel [email protected] 8080 9000 7200
It’s working well, But I’d like not to use eval if it’s possible.
is there another way to call autossh directly and give it the correct params without using eval?