Last active
January 6, 2016 02:56
-
-
Save ajmas/b02bac6437b307e52a2b to your computer and use it in GitHub Desktop.
Script to do both IPv4 and IPv6 host health checks, also supporting hosts that only have one address class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ksh | |
hostname="$1" | |
url_protocol="https://" | |
url_path="/cbace7c0fbe7ffad8af83f61a550dcef/xxxxx_nvwwcsKpsN1qajmbto1_500.jpg" | |
## TODO support CNAMES properly - it throws things off | |
### | |
### IPv4 Health Check | |
### | |
success=0 | |
mesg="" | |
if [[ `host -t A ${hostname}` != *"has no"* ]]; then | |
ping -o $hostname > /dev/null | |
if [ $? == 0 ]; then | |
echo "${url_protocol}${hostname}${url_path}" | |
curl -s -4 --connect-timeout 10 "${url_protocol}${hostname}${url_path}" > /dev/null | |
if [ $? == 0 ]; then | |
success=1 | |
else | |
mesg="failed to get resource via http" | |
success=0 | |
fi | |
else | |
mesg="failed to ping ${hostname}, exit code: $?" | |
success=0; | |
fi | |
echo "IPv4:${hostname} success status: ${success} - ${mesg}" | |
else | |
echo "IPv4:${hostname} no IPv4 address" | |
fi | |
### | |
### IPv6 Health Check | |
### | |
success=0 | |
mesg="" | |
if [[ `host -t AAAA ${hostname}` != *"has no"* ]]; then | |
ping6 -o $hostname > /dev/null | |
if [ $? == 0 ]; then | |
curl -s -6 --connect-timeout 10 "${url_protocol}${hostname}${url_path}" > /dev/null | |
if [ $? == 0 ]; then | |
success=1 | |
else | |
mesg="failed to get resource via http" | |
success=0 | |
fi | |
else | |
mesg="failed to ping6 ${hostname}, exit code: $?" | |
success = 0; | |
fi | |
echo "IPv6:${hostname} success status: ${success} - ${mesg}" | |
else | |
echo "IPv6:${hostname} no IPv4 address" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment