Created
February 20, 2021 23:28
-
-
Save edbentinck/11f962d387ff17e62e88dbc00c60eea6 to your computer and use it in GitHub Desktop.
A bash script to validate a given list of URLs
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/bash | |
# Use: sh validate-urls.sh urls.txt | |
if [[ $# -eq 0 ]] ; then | |
echo 'You must pass the name of a valid text file, containing a list of URLs to be validated.' | |
exit 0 | |
fi | |
while read url | |
do | |
status=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$url") | |
if [ $status == '200' -o $status == '301' -o $status = '302' ] | |
then | |
# Success | |
echo "\033[32m ✔ $status $url" | |
else | |
# Error | |
echo "\033[31m ✗ $status $url" | |
fi | |
done < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment