Skip to content

Instantly share code, notes, and snippets.

@romech
Created March 3, 2021 09:42
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 romech/8b83268524cf5853e9b81daf2c3cb05b to your computer and use it in GitHub Desktop.
Save romech/8b83268524cf5853e9b81daf2c3cb05b to your computer and use it in GitHub Desktop.
Check that ngrok is running. If not, try to restart. Return tunnel urls.
#!/bin/bash
resp=$(curl -sS http://127.0.0.1:4040/api/tunnels || echo 0)
if [[ $resp == "0" ]]; then
echo "Restarting service" >&2
pkill ngrok
screen -dmS ngrok /home/human/ngrok start --all
sleep 90
resp=$(curl -sS http://127.0.0.1:4040/api/tunnels)
fi
tunnel=$(jq '.tunnels[].public_url' <<< "$resp")
if [[ "$tunnel" == "null" ]]; then
echo "nil"
else
echo $tunnel
fi
@MejahMesh256
Copy link

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