summaryrefslogtreecommitdiff
path: root/port-forward/ssh-port-forward.sh
blob: 59350c440512b76f47ce57c0ae2f16185b767081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash

#file will be run from where the user executes the script
j=$1
HOST="root@p.0nom.ch"

# get the process holding the specified port and kill it
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."

ssh $HOST $(for i in $(seq ${j}000 ${j}005); do echo "-R $i:localhost:$i"; done; echo "-R ${j}022:localhost:22")

echo "port forward is available on port {j}00x"

#seperate all the files