On * NIX, you can use curl to request a simple HEAD request ( HEAD requests headers, not the body of the page):
curl --head http:
Then you can take only the first line containing the HTTP status code (200 OK, 404 Not Found, etc.):
curl -s --head http://myurl/ | head -n 1
And then check if you have a decent answer (status code 200 or 3 **):
curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].."
This will lead to the output of the first line if the status code is OK, or nothing if it is not. You can also pass this / dev / null to get the output file, and use $? to determine if it works or not:
curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
EDIT -s simply tells curl not to show a progress bar.
zneak May 27 '10 at 19:59 2010-05-27 19:59
source share