Last active
August 22, 2017 20:51
-
-
Save heywoodlh/b42b4641bf9ff926bba80b61bd8f930b to your computer and use it in GitHub Desktop.
Simple port forwarding script via SSH
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 | |
PORT='80' | |
SSH_PORT='22' | |
USERNAME='root' | |
HOSTNAME='myserver.com' | |
if ssh -p "$SSH_PORT" -t -t -L 9000:127.0.0.1:"$PORT" "$USERNAME"@"$HOSTNAME" & | |
then | |
SSH_PID=$(echo $!) | |
sleep 5 | |
open http://127.0.0.1:9000/ | |
function pause(){ | |
read -p "$*" | |
} | |
pause 'Press [Enter] key to exit...' | |
kill $SSH_PID | |
else | |
echo "ssh connection failed" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment