Created
December 22, 2021 00:22
-
-
Save CodeAlDente/af53ccb889947f4441e9ac6639cc1b9a to your computer and use it in GitHub Desktop.
Check multiple URLs from file using bash
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 | |
# | |
# How to check status of URLs from text file | |
# https://stackoverflow.com/a/25136723 | |
# | |
# This script reads a file with URLs (line-by-line) and checks their http status code | |
# The results will be written to a temporary file locaed in ~/tmp | |
# | |
# takes first argument for file with URLs (line-by-line) | |
URLS_FILE=$1 | |
# you might want to adjust the filepath | |
RESULTS_FILE=~/tmp/$(date +%s%N) | |
if [[ -z ${URLS_FILE} ]] ; then | |
echo "Please provide a file with URLs (line-by-line)!" | |
exit | |
fi | |
if [[ ! -r ${URLS_FILE} ]] ; then | |
echo "File \"${URLS_FILE}\" does not exist or is not readable!" | |
exit | |
fi | |
while read url | |
do | |
urlstatus=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "${url}") | |
# use tabulator as delimiter | |
echo -e "$url\t$urlstatus" >> ${RESULTS_FILE} | |
done < $URLS_FILE | |
echo "Results written to ${RESULTS_FILE}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before you use the script, you should apply permission to execute the file.
Check URLs from file
Work with results
returns only URLs
returns only HTTP status codes
Show all lines NOT containing HTTP status code "200"
Show only URLs NOT containing HTTP status code "200"