-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_links.sh
More file actions
43 lines (36 loc) · 1.13 KB
/
check_links.sh
File metadata and controls
43 lines (36 loc) · 1.13 KB
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
35
36
37
38
39
40
41
#!/bin/bash
for file in $(find /code -name '*.html')
do
#echo $file
for line in $(cat $file)
do
if [[ $line == href* ]]
then
url=`echo $line | sed -ne 's/.*href="\([^"]*\).*/\1/p'`
#` | rev | cut -c 3- | rev`
#echo $url
if [ -z $url ]
then
#echo $line
url=`echo $line | sed -ne "s/.*href='\([^']*\).*/\1/p"`
#echo $url
fi
# bail out on private repos
if [[ ("$url" == *"docker-training/exercises"*) || ("$url" == *"docker-training/presentations"*) || ("$url" == *"docker-training/communication-templates"*) ]]
then
continue
fi
status_code=$(curl -o -I -L -s -w "%{http_code}\n" $url)
#echo $status_code
if [ $status_code -ge "200" ] && [ $status_code -lt "300" ]
then
#echo "status check succeeded"
:
else
echo $file
echo "broken url:" $url
echo "---"
fi
fi
done
done