-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlwatch
executable file
·196 lines (151 loc) · 3.67 KB
/
urlwatch
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#
# urlwatch
#
# v1.4 2002-11-13
#
# Mathieu Lubrano <[email protected]>
#
# This file is GPL.
#
#!/bin/sh
WRKDIR=~/.urlwatch
LOGFILE=$WRKDIR/urlwatch.log
URLFILE=$WRKDIR/urlwatch.conf
EMAIL=""
URLS=""
DEBUG=""
URLID=""
init() {
source /etc/profile 1>/dev/null 2>&1
if [ ! -d $WRKDIR ]; then
mkdir $WRKDIR 1>/dev/null 2>&1
fi
cd $WRKDIR
if [ ! -e $URLFILE ]; then
echo "$URLFILE not found."
exit 1
fi
URLS=`cat $URLFILE`
rm -f $LOGFILE $LOGFILE.body
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Usage:"
echo "$0 [-e [email protected]] [-d] [-u url id]"
echo "-e: send email report to [email protected]"
echo "-d: debug"
echo "-u: check only this url id"
echo " "
echo "Add urls in $WRKDIR/$URLFILE with this format to check urls:"
echo "TheProgramName#http://www.site.com/theWebPage.html"
echo "AnotherOne#http://www.domain.net/rep/"
echo "..."
echo ""
exit 0
fi
if [ "$1" == "-d" ] || [ "$2" == "-d" ] || [ "$3" == "-d" ] || [ "$4" == "-d" ]; then
DEBUG="yes"
else
unset DEBUG
fi
if [ "$1" == "-e" ]; then
EMAIL=$2
fi
if [ "$2" == "-e" ]; then
EMAIL=$3
fi
if [ "$3" == "-e" ]; then
EMAIL=$4
fi
if [ "$1" == "-u" ]; then
URLID=$2
fi
if [ "$2" == "-e" ]; then
URLID=$3
fi
if [ "$3" == "-u" ]; then
URLID=$4
fi
}
checkURLs() {
URLS=`cat $URLFILE`
if [ "$URLID" != "" ]; then
echo "Checking $URLID only..."
fi
for url in $URLS; do
# if the line is a comment, skip to next line
commentTest=`echo $url | cut -b 1`
if [ "$commentTest" == "#" ]; then
continue
fi
theName=${url%#*}
theUrl=${url#*#}
# if URLID is set, just check this one
if [ "$URLID" != "" ] && [ "$URLID" != "$theName" ]; then
# continue (skip test) until we found URLID = theName
continue
fi
echo -n "Checking $theName @ $theUrl..."
if [ ! -d "$theName" ]; then
mkdir $theName 1>/dev/null 2>&1
fi
if [ ! -e "$theName/$theName" ]; then
touch $theName/$theName
fi
mv $theName/$theName $theName/$theName.old 1>/dev/null 2>&1
#wget -q $theUrl -O $theName/$theName
lynx -reload -dump $theUrl 1>$theName/$theName 2>&1
# execute content filtering if any
if [ -e $theName/filter ]; then
cd $theName
source ./filter
cd ..
fi
# avoid first test false alarm
if [ ! -e $theName/$theName.old ]; then
cp $theName/$theName $theName/$theName.old
fi
# avoid false alarm if lynx failed
if [ ! -s $theName/$theName ]; then
cp $theName/$theName.old $theName/$theName
fi
diffs=`diff $theName/$theName $theName/$theName.old`
if [ -n "$DEBUG" ]; then
echo " "
cat $theName/$theName
fi
if [ ! "$diffs" == "" ]; then
echo " <- UPDATED."
echo "$theName $theUrl" >> $LOGFILE
echo "$theName $theUrl" >> $LOGFILE.body
echo " " >> $LOGFILE.body
echo "$diffs" >> $LOGFILE.body
echo "======================================================================" >> $LOGFILE.body
echo " " >> $LOGFILE.body
else
echo "done."
fi
done
if [ -e $LOGFILE ]; then
echo " " >> $LOGFILE
echo "======================================================================" >> $LOGFILE
echo " " >> $LOGFILE
cat $LOGFILE.body >> $LOGFILE
fi
rm -f $LOGFILE.body
}
emailReport() {
if [ -e "$LOGFILE" ]; then
echo -n "Sending email report $$..."
cat $LOGFILE | nail -s "$0 report-$$ changed urls..." $EMAIL
echo "done."
fi
}
main() {
init $*
checkURLs
if [ -n "$EMAIL" ]; then
emailReport
fi
rm -f $LOGFILE $LOGFILE.body
exit 0
}
main $*