Skip to content

Instantly share code, notes, and snippets.

@exalted
Last active February 18, 2021 09:05
Show Gist options
  • Save exalted/149cddbfef3c08c9cc5fd9c0e9cac6c5 to your computer and use it in GitHub Desktop.
Save exalted/149cddbfef3c08c9cc5fd9c0e9cac6c5 to your computer and use it in GitHub Desktop.
healthcheck.sh
#
# USAGE: `healthcheck <name> <URL>`
#
# Minify using http://bash-minifier.appspot.com
healthcheck() {
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
COLOR_RESET='\033[0m'
while [[ true ]]; do
started_at="$(date +"%Y-%m-%dT%H:%M:%SZ") (Local time)"
SECONDS=0
output=$(curl --fail --silent --show-error --stderr - $2)
result=$?
if [[ $result -ne 0 ]]; then
echo -e $RED
elif [[ $SECONDS -le 1 ]]; then
echo -e $GREEN
elif [[ $SECONDS -le 2 ]]; then
echo -e $YELLOW
else
echo -e $RED
fi
if [[ $result -eq 0 ]] && [[ $SECONDS -le 1 ]]; then
echo "$started_at: $1: $output"
else
echo "Name : $1"
echo "Started at : $started_at"
echo "Took : $SECONDS seconds"
echo "Output : $output"
fi
echo -e $COLOR_RESET
if [[ $SECONDS -eq 0 ]]; then
sleep 1;
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment