Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Last active February 9, 2021 18:10
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 kasparsd/9b22ba2f3414f00c94cc635498303379 to your computer and use it in GitHub Desktop.
Save kasparsd/9b22ba2f3414f00c94cc635498303379 to your computer and use it in GitHub Desktop.
Basic uptime monitor
#!/bin/bash
NOTIFY_FROM="no-reply@example.com"
NOTIFY_TO="hi@example.com"
URLS=(
"https://example.com"
"https://google.com"
)
function is_up {
curl -s --head --request GET "$1" | grep "200 OK"
}
REPORT=""
for URL in "${URLS[@]}"
do
echo "Checking $URL"
if ! is_up "$URL"; then
REPORT+=" Down: $URL "
fi
done
if [ -n "$REPORT" ]; then
echo "$REPORT" | mail -r "$NOTIFY_FROM" -s "Sites down report" "$NOTIFY_TO"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment