One-line shell script to get the HTTP status of multiple sites

Had this come up with a client recently…

A software vulnerability was discovered that could—potentially—result in a WordPress site throwing 500 errors. My client operates dozens of sites and needed to know if any of their sites were affected. Shell to the rescue.

First, I exported a complete list of sites from their host (WP Engine) as a CSV, then copied the URL column into a file called hosts.txt. One host per line, something like this:

Then I ran this shell script to loop over each line and use curl to get the HTTP status of each site:

Which produced this output:

Interesting bits include:

  • You can disable curl’s timer output by appending the -s flag
  • Adding -n to echo will trim off the trailing newline character and adding -e will render escape characters in the output (like \t to get a tab).

Leave a Comment

Scroll to Top