Skip to content

Instantly share code, notes, and snippets.

@nicolae-olariu
Created December 21, 2017 10:42
Show Gist options
  • Save nicolae-olariu/b833b57ba5fd1d82e7cae5cbee47cba3 to your computer and use it in GitHub Desktop.
Save nicolae-olariu/b833b57ba5fd1d82e7cae5cbee47cba3 to your computer and use it in GitHub Desktop.
bash: bulk test redirects
Based on (this answer)[https://stackoverflow.com/a/28100010/2674883]:
One solution :
csv:
http://google.com;http://www.google.fr
http://domain.null;http://www.domain.null
code:
#!/bin/bash
while IFS=";" read -r url1 url2; do
ret=$(curl -s -o /dev/null -w "%{http_code}\n" "$url1")
((ret >= 200 && ret <= 400)) && echo 'url1 PASS' || echo 'url1 FAIL'
echo "url2 $(curl -s -L -o /dev/null -w "%{http_code}\n" "$url2")"
done < csv
If you need to know the real URL redirected (or not), use
curl -L -s -o /dev/null http://google.fr -w "%{url_effective}\n"
Feel free to improve to fit your needs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment