Skip to content

Instantly share code, notes, and snippets.

@fcsest
Created April 14, 2022 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcsest/4223ae0e23a5bcf2cc32f16ff4478903 to your computer and use it in GitHub Desktop.
Save fcsest/4223ae0e23a5bcf2cc32f16ff4478903 to your computer and use it in GitHub Desktop.
Start ngrok connection in background in fish shell with "source start_ngrok.sh".
#!/bin/sh
set NGROK_PUBLIC_URL ""
echo "Start ssh-access ngrok in background"
nohup ngrok start ssh-access &>/dev/null &
echo -e "Extracting ngrok port..."
while [ -z "$NGROK_PUBLIC_URL" ];
sleep 1
# Run 'curl' against ngrok API and extract public (using 'sed' command)
set NGROK_PUBLIC_URL $(curl --silent --max-time 10 --connect-timeout 5 \
--show-error http://127.0.0.1:4040/api/tunnels | \
sed -nE 's/.*ngrok.i..([^"]*).*/\1/p')
end
echo "ngrok port => $NGROK_PUBLIC_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment