Last active
February 13, 2019 16:15
-
-
Save silvernode/4d3e7fe1adc2d2a7123249a025cd651d to your computer and use it in GitHub Desktop.
[Bash] Check if a site is online or offline
This file contains hidden or 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/bash | |
FAIL_CODE=6 | |
if [ -z "${1}" ];then | |
echo "usage: ${0} example.com" | |
exit | |
fi | |
check_status(){ | |
LRED="\033[1;31m" # Light red | |
LGREEN="\033[1;32m" #Light green | |
NC='\033[0m' # No Color | |
curl -sf "${1}" > /dev/null | |
if [ ! $? = ${FAIL_CODE} ];then | |
echo -e "${LGREEN}${1} is online${NC}" | |
else | |
echo -e "${LRED}${1} is down${NC}" | |
fi | |
} | |
check_status "${1}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment