-
Notifications
You must be signed in to change notification settings - Fork 23
/
link_verifier.sh
34 lines (28 loc) · 968 Bytes
/
link_verifier.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# This script checks all links in the markdown files
RED='\033[0;31m'
NC='\033[0m' # No Color
function search_file() {
link_lines=`cat $1 | grep https://`
for line in $link_lines; do
if [[ $line == *"https://"* ]]; then
line=`echo $line | sed -e 's/.*https:/https:/g'`
line=`echo $line | sed -e 's/[\)| |\`|"].*//g'`
if [[ $line == *"https://crates.io"* ]]; then
echo " ? Unknown: $line (crates.io blocks curl)"
continue
fi
code=`curl -s -o /dev/null -w "%{http_code}" "$line"`
if [[ "$code" == "200" ]]; then
echo " - Success: $line"
elif [[ "$code" == "301" ]]; then
echo " + MOVED: $line"
else
echo -e " ! ${RED}FAILURE:${NC} $line (code: $code)"
fi
fi
done
}
for FILE in `find src/ -name "*.md"`; do
search_file $FILE
done