#!/bin/bash # Check if at least one argument is provided if [ $# -lt 1 ]; then echo "Usage: $0 [additional_ports...]" echo "Example: $0 5 80 443" exit 1 fi # First argument is the base number for port range j=$1 shift # Remove first argument from the list, leaving only additional ports HOST="root@p.0nom.ch" # Clean management port echo "cleaning management port..." ssh $HOST "ss -tunlp | grep :${j}022 | awk '{print $NF}' | sed 's/.*pid=\([^,]*\).*/\1/' | head -n1 | xargs kill -9" echo "cleaning attempted." # Build the SSH command with all port forwards SSH_CMD="ssh $HOST" # Add range-based port forwards (j000-j005) for i in $(seq ${j}000 ${j}005); do SSH_CMD+=" -R $i:localhost:$i" done # Add management port forward SSH_CMD+=" -R ${j}022:localhost:22" # Add additional individual port forwards from remaining arguments for port in "$@"; do SSH_CMD+=" -R $port:localhost:$port" done # Execute the SSH command eval $SSH_CMD echo "Port forwards are available on:" echo "- Ports ${j}000-${j}005" echo "- Management port ${j}022" if [ $# -gt 0 ]; then echo "- Additional ports: $@" fi