Skip to content

Instantly share code, notes, and snippets.

@jakeasmith
Last active December 15, 2015 01:29
Show Gist options
  • Save jakeasmith/5180095 to your computer and use it in GitHub Desktop.
Save jakeasmith/5180095 to your computer and use it in GitHub Desktop.
I threw this together to monitor an intermittent LB issue tonight. It works beautifully.
#!/bin/bash
# Usage: ./command.sh http://www.google.com
# Help: Returns the HTTP status code for a given URL every 2 seconds
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset.
while [ 1 ];
do
response=$(curl -sL -w "%{http_code} %{url_effective}\\n" "$1" -o /dev/null)
if [[ "$response" == *"200"* ]]
then
echo "${txtgrn} $response ${txtrst} - $(date)"
else
echo "${txtred} $response ${txtrst} - $(date)"
fi
sleep 2;
done
@jakeasmith
Copy link
Author

I left the color codes in there in case someone wants to add more later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment