-
-
Save hongster/5b9b44b1edeb75c93f9c9c9119a7ca1b to your computer and use it in GitHub Desktop.
Reestablish SSH tunnel connection when disconnected.
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
#!/usr/bin/env bash | |
remoteUser="foobar" | |
remoteHost="example.com" | |
count=$(pgrep -U $(id -u) -a -f "$remoteHost" -c) | |
if [[ $count -eq 0 ]];then | |
echo "Restarting SSH runnel" | |
ssh -f -N -R 2022:localhost:22 ${remoteUser}@${remoteHost} -o ServerAliveInterval=30 -o ServerAliveCountMax=1 -o ExitOnForwardFailure=yes | |
else | |
echo "SSH tunnel running" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment