30 lines
663 B
Bash
Executable File
30 lines
663 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Function to display usage information
|
|
usage() {
|
|
echo "Usage: $0 <user@host> <port1> [port2] [port3] ..."
|
|
exit 1
|
|
}
|
|
|
|
# Ensure at least two arguments are provided: host and one port
|
|
if [ "$#" -lt 2 ]; then
|
|
usage
|
|
fi
|
|
|
|
# Extract the host from the first argument
|
|
HOST="$1"
|
|
shift # Shift the arguments so that $@ contains the remaining ports
|
|
|
|
# Initialize the PORTS variable
|
|
PORTS=""
|
|
|
|
# Iterate over the remaining arguments, which are the ports
|
|
for port in "$@"; do
|
|
PORTS="$PORTS -L ${port}:localhost:${port}"
|
|
done
|
|
|
|
# Construct and run the SSH command
|
|
SSH_CMD="ssh -N -T -o ExitOnForwardFailure=yes $HOST $PORTS"
|
|
echo "Running: $SSH_CMD"
|
|
$SSH_CMD
|