0

I am trying to run a curl command on each line of a file. Each line is one url. I then want to output the url if the http status is 404. Here is my script so far:

while read LINE; do                                                                              
        curl -o /dev/null --silent --head --write-out '%{http_code}' "$LINE"                     
        if [[ $LINE == *"404"* ]]                                                                
        then                                                                                     
                echo $LINE                                                                       
        fi                                                                                       
done < sites.txt

Currently, that just outputs the http status of each url. If I remove the if/then and keep the echo $LINE, I get the http status plus the url. I want the url to be shown but only if it has a status of 404.

user715564
  • 1,650
  • 2
  • 25
  • 60

0 Answers0