root/misc/cronrss

Revision 972, 2.9 kB (checked in by alpt, 2 years ago)

stuff

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/bin/bash
2 #
3 #                        Cronrss
4 #                   Old style RSS feed
5 #
6 # http://freaknet.org/alpt/src/utils/cronrss
7 #
8 # It verifies if the web page pointed by a given URL has changed.
9 # If it has, cronrss will send a notice email to you.
10 # The URL list is kept in the ~/.cronrss/url text file (one URL per line).
11 #
12 # It is very useful to use URLs which point to rss feeds.
13 #
14 # *** Usage:
15 #
16 # 1) Put all the URLs you want to check in the ~/.cronrss/url text file (one
17 #    URL per line).
18 #
19 # 2) Run cronrss
20 #
21 #          cronrss [-d [seconds]]
22 #
23 # If the `-d' option is specified, it will check periodically the URLs.
24 # You can specify its frequency in seconds (default is 1800s = 30min)
25 #
26 #          cronrss update
27 #
28 # Each time you modify the url_list, you have to run `cronrss update`
29 #
30 # *** Examples:
31 #
32 #        echo http://www.hackaday.org >> ~/.cronrss/url
33 #        cronrss update
34 #        cronrss -d
35 #        # From this point on, whenever hackday.org changes you will get an email
36 #        # which shows you the text differences
37 #        # Since hackaday has a rss feed it is better to use this URL instead:
38 #        # http://www.hackaday.com/rss.xml
39 #
40 # *** Links:
41 #
42 #       This webservice maybe useful:
43 #               http://page2rss.com/
44 #
45 # PS: the idea of Cronrss was initially published on Idiki:
46 # http://idiki.dyne.org/wiki/Cronrss
47 #
48 #
49 # AlpT (@freaknet.org)
50 #
51
52
53 #
54 #
55 ## Configure here
56 #
57
58 dir=`echo ~/.cronrss`   # cronrss stuff is saved in this directory
59 dump="$dir/dump"        # dumps of the web pages
60 url_list="$dir/url"     # url list file
61
62 mail_to="`whoami`"      # this is the email address where the notice is sent
63 #mail_to="foo@bar.org`"
64 mail_subject="Cronrss digest" 
65
66 #
67 ##
68 #
69 #
70
71 check_it() {
72         local notice
73
74         if [ "$1" == "no_notice" ]
75         then
76                 notice=0
77         else
78                 notice=1
79         fi
80
81         if [ ! -d $dump ]
82         then
83                 mkdir -p $dump/
84         fi
85
86         for i in `cat $url_list`
87         do
88                 md5=`echo "$i" | md5sum | cut -d ' ' -f 1`
89
90                 rm -f $dump/old-$md5                    &> /dev/null
91                 mv -f $dump/new-$md5 $dump/old-$md5     &> /dev/null
92                 links -dump "$i" > $dump/new-$md5
93
94                 if [ "$?" != "0" ] || [ ! -f $dump/old-$md5 ] || [ ! -f $dump/new-$md5 ]
95                 then
96                         continue
97                 fi
98
99                 diff -q $dump/old-$md5 $dump/new-$md5   &> /dev/null
100                 if [ "$?" == 1 ] && [ "$notice" == "1" ]
101                 then
102                         local t
103                         t=`tempfile`
104
105                         echo "$i changed"                     > $t
106                         echo ""                               >> $t
107                         diff -u $dump/old-$md5 $dump/new-$md5 >> $t
108
109                         cat $t | mail -s "$mail_subject" $mail_to
110
111                         rm $t
112                 fi
113         done
114 }
115
116 if test "$1" = "help" -o "$1" = "-h" -o "$1" = "--help"
117 then
118         echo "Usage:"
119         echo "        cronrss [-d [seconds]]"
120         echo "        cronrss update"
121         echo ""
122         echo " If the \"-d\" option is specified, it will check periodically the URLs."
123         echo " You can specify its frequency in seconds (default is 1800s = 30min)"
124         echo ""
125         echo " Each time you modify the url_list, you have to run \"cronrss update\""
126         exit 1
127 fi
128
129 if [ "$1" == "-d" ]
130 then
131         seconds=1800
132         if [ ! -z "$2" ]
133         then
134                 seconds=$2
135         fi
136
137         while true
138         do
139                 check_it
140                 sleep $seconds
141         done
142 elif [ "$1" == "update" ]
143 then
144        
145         check_it no_notice
146 else
147         check_it
148 fi
Note: See TracBrowser for help on using the browser.