Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tedeh
Created January 6, 2019 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedeh/51de8d111cf3e8c0bf89cf14851d244f to your computer and use it in GitHub Desktop.
Save tedeh/51de8d111cf3e8c0bf89cf14851d244f to your computer and use it in GitHub Desktop.
Gets a list of domains with curl, sending an email if the curl exit code is non-zero
#!/bin/bash
ERROR_EMAIL="billg@microsoft.com"
DOMAINS=(
"https://github.com"
)
ERRORED_DOMAINS=()
# joins the rest of the input args with the first arg
function join_by { local IFS="$1"; shift; echo "$*"; }
for i in "${DOMAINS[@]}"
do
DOMAIN="$i"
curl --silent --output /dev/null $DOMAIN
STATUS="$?"
if [ "$STATUS" -ne 0 ]; then
echo "`date +\"%Y-%m-%d %H:%M:%S\"` $DOMAIN curl-exit-code=$STATUS"
ERRORED_DOMAINS+=("$DOMAIN curl-exit-code=$STATUS")
else
echo "`date +\"%Y-%m-%d %H:%M:%S\"` $DOMAIN curl-exit-code=$STATUS"
fi
done
if [ ${#ERRORED_DOMAINS[@]} -eq 0 ]; then
echo "`date +\"%Y-%m-%d %H:%M:%S\"` No errors found"
else
echo "`date +\"%Y-%m-%d %H:%M:%S\"` Errors found, emailing $ERROR_EMAIL"
BODY=$(join_by $'\n' "${ERRORED_DOMAINS[@]/#/}" "$1")
echo "$BODY" | mail -E -s "check_domains error" $ERROR_EMAIL
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment