Last active
November 26, 2015 01:08
-
-
Save eungjun-yi/2cbf748a6e68f3a958d5 to your computer and use it in GitHub Desktop.
Detecting broken links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
while getopts v OPTION ; | |
do | |
case "$OPTION" in | |
v) VERBOSE=true ; shift ;; | |
esac | |
done | |
urls=$(grep -i -E -o 'https?://[^ )]*[^), ]' $1) | |
# HEAD may be better for performance but sometimes does not work. | |
method="GET" | |
for url in $urls | |
do | |
test $VERBOSE && echo test: $url | |
status_line=`curl -s -I -X $method $url | head -n1` | |
result1=$? | |
test $VERBOSE && echo status: $status_line | |
echo $status_line | grep '^\S* [23][0-9][0-9]' > /dev/null | |
result2=$? | |
[ $result1 -ne 0 -o $result2 -ne 0 ] && echo $url | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment