-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcheck_links.sh
More file actions
executable file
·33 lines (28 loc) · 986 Bytes
/
check_links.sh
File metadata and controls
executable file
·33 lines (28 loc) · 986 Bytes
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
#!/bin/bash
# Oh SWEET. Color codes! Ganked from http://stackoverflow.com/a/10466960/263969
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
ok() {
echo -e "${RESTORE}[${GREEN}OK${RESTORE}]"
}
fail() {
echo -e "${RESTORE}[${RED}FAIL${RESTORE}]"
}
# Go through the XML sources and grep for links (using a positive look-behind
#
# grep will output "filename:line match", so remove the "filename:" part with cut
grep -P -r -o '(?<=href=")(http://[^"]*)' docbook | cut -d: -f 2- | \
# In XML we have to escape ampersands with &, use sed to reverse that
sed 's/\&/\&/g' | \
# Remove references to anything from me
grep -vE '(lnx|tbielawa)' | \
# Loop over each URL
while read line; do
echo -n "${line} ... "; curl --connect-timeout 15 -f ${line} &>/dev/null; # Curl each URL and return a special code if not found
if [ "${?}" == "0" ]; then # 0 return status means we found it, else it wasn't found
ok
else
fail
fi
done