Advertisement
CastelShal

connectsh

Mar 12th, 2024 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2. url=172.16.128.48
  3. while getopts ":p:" opt; do
  4.   case $opt in
  5.     p)
  6.     if [[ ! $OPTARG =~ ^[0-9]+$ ]]; then
  7.         echo "Error: -p argument must be a number."
  8.         exit 1
  9.       fi
  10.       port="$OPTARG"
  11.       ;;
  12.     \?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
  13.   esac
  14. done
  15.  
  16. # Check if port is provided and validate
  17. if [ -z "$port" ]; then
  18.   echo "Error: Please provide a port number using -p flag."
  19.   exit 1
  20. fi
  21.  
  22. ssh-copy-id -p $port ubuntu@$url
  23. clear
  24. echo "Connected Successfully. Visit localhost:[8080|8929|9001]"
  25. echo "To terminate this process, use Ctrl-C. Exiting otherwise will leave ports occupied"
  26. ssh -N -L 8080:127.0.0.1:8080 -p $port ubuntu@$url &
  27. ssh -N -L 8929:172.19.0.3:8929 -p $port ubuntu@$url &
  28. ssh -N -L 9001:172.19.0.2:80 -p $port ubuntu@$url
  29. kill $(jobs -p)  # Get PIDs of all background jobs and send SIGTERM
  30. jobs
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement