diff --git a/Linux/url-check/url-check.py b/Linux/url-check/url-check.py new file mode 100644 index 0000000..a00d8d3 --- /dev/null +++ b/Linux/url-check/url-check.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import argparse +import requests + +parser = argparse.ArgumentParser(description='Make an HTTP request and retry a health check if successful.') +parser.add_argument('url', help='the URL to request') +parser.add_argument('--hs', help='the health check URL') + +args = parser.parse_args() + +response = requests.get(args.url) + +if response.status_code == 200: + if args.hs: + retry_count = 3 + while retry_count > 0: + try: + requests.get(args.hs) + break + except requests.exceptions.RequestException: + retry_count -= 1 + else: + print('Health check URL not provided, skipping...') +else: + print(f'HTTP status code is {response.status_code}, aborting...') + exit(1) diff --git a/Linux/url-check/url-check.sh b/Linux/url-check/url-check.sh new file mode 100644 index 0000000..b5c0cce --- /dev/null +++ b/Linux/url-check/url-check.sh @@ -0,0 +1,25 @@ +#!/usr/bin/csh -f +set MODE=$1 +set CURL=/usr/bin/curl + +if ($MODE == no_auth) then + set URL=$2 + set HS=$3 + set STATUS=`$CURL -L -o /dev/null -s -w "%{http_code}\n" -m 1 $URL` + + else if ($MODE == auth) then + set AUTH=$2 + set URL=$3 + set HS=$4 + set STATUS=`$CURL -L -o /dev/null -s -w "%{http_code}\n" -m 1 --user $AUTH $URL` + + else + exit 1 +endif + +if ($STATUS == 200) then + $CURL -fsS --retry 3 $HS > /dev/null + else + exit 1 +endif +