h8rt3rmin8r

ngrok-status.sh

Oct 20th, 2020
816
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env bash
  2. #>
  3. #> [ ngrok-status ]
  4. #>
  5. #>    Display the status of ngrok (outputs either "ACTIVE" or "INACTIVE")
  6. #>
  7. #>    No inputs are required when invoking this script.
  8. #>
  9.  
  10. function help_text() {
  11.     cat "$0" \
  12.         | grep -E '^#[>]' \
  13.         | sed 's/^..//'
  14.  
  15.     return $?
  16. }
  17.  
  18. function status_check() {
  19.     ps -aux \
  20.         | tr -s '\t' ' ' \
  21.         | tr -s ' ' ' ' \
  22.         | sed '/grep/d' \
  23.         | sed '/ngrok-status/d' \
  24.         | grep -E 'ngrok' &>/dev/null
  25.  
  26.     return $?
  27. }
  28.  
  29. if [[ "${1}" =~ ^[-][hH]$ || "${1}" =~ ^[-]help$ ]]; then
  30.     help_text
  31.  
  32.     exit $?
  33. fi
  34.  
  35. status_code=$(status_check; echo $?)
  36.  
  37. if [[ "${status_code}" -eq 0 ]]; then
  38.     echo "ACTIVE"
  39.  
  40.     exit 0
  41. else
  42.     echo "INACTIVE"
  43.  
  44.     exit 1
  45. fi
  46.  
RAW Paste Data