Created
September 26, 2013 20:03
-
-
Save nopivnick/6719772 to your computer and use it in GitHub Desktop.
A bash script for keeping a reverse SSH tunnel initiated by a machine behind a firewall persistent. If you wanted multiple tunnels (i.e., to multiple hosts) you might paramaterize this then have separate scripts named for each host (e.g., ssh-reverse-persist_host-1.sh, ssh-reverse-persist_host-2.sh) that called ssh-reverse-persist.sh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
createTunnel() { | |
/usr/bin/ssh -t -t -R 19999:localhost:22 user@example.com | |
if [[ $? -eq 0 ]]; then | |
echo Tunnel to example.com created successfully | |
else | |
echo An error occurred creating a tunnel to example.com RC was $? | |
fi | |
} | |
## to see if the tunnel is running. If it returns non-zero, then create a new connection | |
ps x | grep "19999\:localhost\:22" | |
if [[ $? -ne 0 ]]; then | |
echo Creating new tunnel connection | |
createTunnel | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment