Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Created June 14, 2012 21:08
Show Gist options
  • Save ifesdjeen/2932963 to your computer and use it in GitHub Desktop.
Save ifesdjeen/2932963 to your computer and use it in GitHub Desktop.
Persistent SSH Tunnel
HOST = # masked
SOURCE_PORT = 5672
DESTINATION_PORT = 5672
USERNAME = ifesdjeen
createTunnel() {
/usr/bin/ssh -f -N -L$SOURCE_PORT:$HOST:$DESTINATION_PORT -L19922:HOST:22 ifesdjeen@$HOST
if [[ $? -eq 0 ]]; then
echo Tunnel to $HOST created successfully
else
echo An error occurred creating a tunnel to $HOST RC was $?
fi
}
/usr/bin/ssh -p 19922 $USERNAME@localhost ls
if [[ $? -ne 0 ]]; then
echo Creating new tunnel connection
createTunnel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment