forked from epety/100-shell-script-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path077-checklinks.sh
More file actions
executable file
·31 lines (23 loc) · 878 Bytes
/
077-checklinks.sh
File metadata and controls
executable file
·31 lines (23 loc) · 878 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
#!/bin/sh
# checklinks - traverse all internal URLs on a Web site, reporting
# any errors in the "traverse.errors" file.
lynx="/usr/local/bin/lynx" # this might need to be tweaked
# remove all the lynx traversal output files upon completion:
trap "/bin/rm -f traverse*.errors reject*.dat traverse*.dat" 0
if [ -z "$1" ] ; then
echo "Usage: checklinks URL" >&2 ; exit 1
fi
$lynx -traversal "$1" > /dev/null
if [ -s "traverse.errors" ] ; then
echo -n $(wc -l < traverse.errors) errors encountered.
echo \ Checked $(grep '^http' traverse.dat | wc -l) pages at ${1}:
sed "s|$1||g" < traverse.errors
else
echo -n "No errors encountered. ";
echo Checked $(grep '^http' traverse.dat | wc -l) pages at ${1}
exit 0
fi
baseurl="$(echo $1 | cut -d/ -f3)"
mv traverse.errors ${baseurl}.errors
echo "(A copy of this output has been saved in ${baseurl}.errors)"
exit 0