Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TerenceLiu98/0c7746f130666c8e5a81601bd6b26b2a to your computer and use it in GitHub Desktop.
Save TerenceLiu98/0c7746f130666c8e5a81601bd6b26b2a to your computer and use it in GitHub Desktop.
jupyter&code-server.sh
#### AUTOMATIC TUNNEL WITH CLOUDFLARE SCRIPT ####
jupyterhub & cloudflared tunnel --url http://localhost:8000
code-server --auth=none -p 8001 & cloudflared tunnel --url http://localhost:8001
@TerenceLiu98
Copy link
Author

TerenceLiu98 commented Jul 16, 2021

getport.sh

#!/bin/bash
 
PORT=0
function Listening {
   TCPListeningnum=`netstat -an | grep ":$1 " | awk '$1 == "tcp" && $NF == "LISTEN" {print $0}' | wc -l`
   UDPListeningnum=`netstat -an | grep ":$1 " | awk '$1 == "udp" && $NF == "0.0.0.0:*" {print $0}' | wc -l`
   (( Listeningnum = TCPListeningnum + UDPListeningnum ))
   if [ $Listeningnum == 0 ]; then
       echo "0"
   else
       echo "1"
   fi
}
 
function random_range {
   shuf -i $1-$2 -n1
}
 
function get_random_port {
   templ=0
   while [ $PORT == 0 ]; do
       temp1=`random_range $1 $2`
       if [ `Listening $temp1` == 0 ] ; then
              PORT=$temp1
       fi
   done
   #echo "port=$PORT"
}
get_random_port 1 10000;

webcode.sh

#!/bin/bash
. getport.sh
echo "PORT:" $PORT
code-server --port $PORT --host=0.0.0.0 --auth=none & cloudflared tunnel --url http://localhost:$PORT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment