-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeadlinkstat.bash
executable file
·91 lines (78 loc) · 1.84 KB
/
deadlinkstat.bash
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
function execdb() {
echo "$1" | sqlite3 "$DATABASE"
}
if [ "$1" = "" ]
then
DATABASE="deadlink.db"
else
DATABASE="$1"
fi
if [ ! -f "$DATABASE" ]
then
printf -- "Database '%s' not found!\n" "$DATABASE"
exit 1
fi
baselink=$(execdb "
SELECT childurl
FROM parent
WHERE parenturl = ''
OR parenturl IS NULL;
")
countlink=$(execdb "
SELECT COUNT(*)
FROM link;
")
counthtmlpage=$(execdb "
SELECT COUNT(*)
FROM link
WHERE contenttype LIKE 'text/html%';
")
countcheckedlink=$(execdb "
SELECT COUNT(*)
FROM link
WHERE checkdate IS NOT NULL
OR parsedate IS NOT NULL;
")
countexternallink=$(execdb "
SELECT COUNT(*)
FROM link
WHERE url NOT LIKE '$baselink%';
")
mostuseddeadlink=$(execdb "
SELECT childurl
FROM parent, link
WHERE url = childurl
AND httpcode IN (0, 404)
GROUP BY childurl
HAVING COUNT(parenturl) > 30;
")
httpcode=$(execdb "
SELECT ' - '
|| code.httpcode
|| ' '
|| code.description
|| ': '
|| COUNT(*)
FROM link, code
WHERE code.httpcode = link.httpcode
GROUP BY link.httpcode
ORDER BY link.httpcode ASC;
")
linktype=$(execdb "
SELECT ' - '
|| CASE WHEN contenttype = '' THEN '[unknown]' ELSE contenttype END
|| ': '
|| COUNT(*)
FROM link
GROUP BY contenttype;
")
printf -- '\nStatistics for %s\n\n' "$baselink"
printf -- '- Links: %d\n' "$countlink"
printf -- '- External links: %d\n' "$countexternallink"
printf -- '- HTML pages: %d\n' "$counthtmlpage"
printf -- '- Checked links: %d\n' "$countcheckedlink"
printf -- '- Most used dead links:\n%s\n' "$mostuseddeadlink"
printf -- '- HTTP codes:\n%s\n' "$httpcode"
printf -- '- Content types:\n%s\n' "$linktype"
printf -- '\n'