Skip to content

Instantly share code, notes, and snippets.

@aozimkov
Last active June 18, 2018 11:33
Show Gist options
  • Save aozimkov/ae9955d735eb1e08a8a61f2c066606a7 to your computer and use it in GitHub Desktop.
Save aozimkov/ae9955d735eb1e08a8a61f2c066606a7 to your computer and use it in GitHub Desktop.
Simple bash script checks http 200 response code for urls from file
#!/bin/bash
## This script simply gets a line (with url) from
## the file setted as parameter and checks its url
## response code
##
## example: ./script.sh urls.txt
##
## https://github.com/aozimkov
##
## *************************************************
checker(){
RESPONSE_CODE=$(curl --write-out %{http_code} --silent --output /dev/null $1)
CODENUM=$2
if [ "$RESPONSE_CODE" != "$CODENUM" ]; then
echo "$LINE : $CODENUM"
fi
}
if [ -z $2 ];
then
CODE=$2
else
CODE=200
fi
while read LINE; do checker "$LINE" "$CODE"; done < $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment