Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL 404 Checker for bash

I want to write some code i can run in the bash that takes a list of URL's and checks if they return a 404. If the site is not returning a 404 i need the url to be written to the output list.

So in the end i should have a list with working sites. I do not know how to realize the code. This looks like something that could work right?: How to check if a URL exists or returns 404 with Java?

like image 591
xxad Avatar asked Oct 29 '25 10:10

xxad


1 Answers

You can use this code and build on it as necessary:

#!/bin/bash

array=( "http://www.stackoverflow.com" "http://www.google.com" )

for url in "${array[@]}"
do
    if ! curl -s --head  --request GET ${url} | grep "404 Not Found" > /dev/null
    then
       echo "Output URL not returning 404 ${url}"
    fi
done
like image 137
tale852150 Avatar answered Oct 31 '25 02:10

tale852150



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!