Skip to content

Instantly share code, notes, and snippets.

@silvernode
Last active February 13, 2019 16:15
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 silvernode/4d3e7fe1adc2d2a7123249a025cd651d to your computer and use it in GitHub Desktop.
Save silvernode/4d3e7fe1adc2d2a7123249a025cd651d to your computer and use it in GitHub Desktop.
[Bash] Check if a site is online or offline
#!/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