#!/bin/bash # Get the first parameter as LOCAL_PORT (default to 25565 for Minecraft) LOCAL_PORT=${1:-25565} # Get the second parameter as OFFSET (default to 0 so public port == local port) OFFSET=${2:-0} # Calculate the PUBLICPORT by adding the OFFSET to the LOCAL_PORT PUBLICPORT=$(($LOCAL_PORT + OFFSET)) # SSH host alias (defined in ~/.ssh/config) SSH_HOST="spotbot" echo " $SSH_HOST:$PUBLICPORT --> localhost : $LOCAL_PORT " # Run SSH command to create a reverse tunnel from the server while true; do autossh -M 0 -N \ -R 0.0.0.0:$PUBLICPORT:localhost:$LOCAL_PORT \ -o "ServerAliveInterval 20" -o "ServerAliveCountMax 3" \ $SSH_HOST sleep 5 done