Created
July 17, 2017 18:15
-
-
Save rodmcnew/521549841e4c9199dd257254cdae313e to your computer and use it in GitHub Desktop.
socks-ssh-tunnel.bash
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
#Fill in these two vars and then set this script to run every minute in cron | |
REMOTE_HOST="somewhere.com" | |
LOCAL_PORT="12345" | |
#Leave this part alone | |
SSH_ARGS="$REMOTE_HOST -D $LOCAL_PORT -f -C -q -N" | |
START_COMMAND="ssh $SSH_ARGS" | |
echo "" | |
echo "Start command:" | |
echo $START_COMMAND | |
echo "" | |
echo 'Stop command:' | |
echo "pkill -f 'ssh $SSH_ARGS'" | |
echo "" | |
CHECK="ps -e | grep --quiet \"[ssh] $SSH_ARGS\"" | |
if eval $CHECK; then | |
echo "The tunnel is already running on local port $LOCAL_PORT." | |
exit | |
fi | |
eval $START_COMMAND | |
echo "The tunnel has been started on local port $LOCAL_PORT." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment