File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ check_link_file ()
4
+ {
5
+ if ! [ -f " ${EXTERNAL_LINK_FILE} " ]; then
6
+ echo " The specified file $EXTERNAL_LINK_FILE does not exist. Exiting..."
7
+ exit 1
8
+ fi
9
+ }
10
+
11
+
12
+ check_urls ()
13
+ {
14
+ echo " Checking validity of external links..."
15
+
16
+ local URLS+=($( grep ' url:' $EXTERNAL_LINK_FILE | tail -n+1 | awk ' { print $2}' ) )
17
+
18
+ if [ ${# URLS[@]} == 0 ]; then
19
+ echo " No links found in $EXTERNAL_LINK_FILE , please check."
20
+ exit 1
21
+ fi
22
+
23
+ for url in " ${URLS[@]} " ;
24
+ do
25
+ response=$( curl -o /dev/null -s -w " %{http_code}\n" $url )
26
+
27
+ if [[ " $response " == " 000" || " $response " > " 399" ]]; then
28
+ echo " ($response ) $url is not a live url, please check in $EXTERNAL_LINK_FILE ."
29
+ INVALID=$(( INVALID+ 1 ))
30
+ fi
31
+
32
+ sleep .5
33
+ done
34
+
35
+ if [[ " $INVALID " == 0 ]]; then
36
+ echo " Every link is alive and OK."
37
+ else
38
+ echo " $INVALID invalid links found."
39
+ fi
40
+ }
41
+
42
+
43
+ if ! [ " $# " -eq 1 ]; then
44
+ echo " Usage: $0 <external link file>"
45
+ exit 1
46
+ fi
47
+
48
+ EXTERNAL_LINK_FILE=" ${1} "
49
+ INVALID=0
50
+
51
+ check_link_file
52
+ check_urls
53
+
54
+ exit 0
You can’t perform that action at this time.
0 commit comments