Skip to content

Instantly share code, notes, and snippets.

@edbentinck
Created February 20, 2021 23:28
Show Gist options
  • Save edbentinck/11f962d387ff17e62e88dbc00c60eea6 to your computer and use it in GitHub Desktop.
Save edbentinck/11f962d387ff17e62e88dbc00c60eea6 to your computer and use it in GitHub Desktop.
A bash script to validate a given list of URLs
#!/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