aboutsummaryrefslogtreecommitdiff
path: root/hpUpdateNotify
blob: f7f601cd8b4d3f9969fba8118f5d8a6a9782f134 (plain)
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
#!/bin/bash

#####################################################
## hpUpdateNotify ###################################
#####################################################
# Checks for changed websites and notifies via mail #
#####################################################

# where do you want to keep your files?
cwd="~/hpUpdateNotify/"

# add any homepage (its name) you want to be notified about
files=( "foobar" )

# and just put the address in the array below at the corresponding index
addresses=( "http://www.foobar.com" )

lastIndex=`expr ${#addresses[@]} - 1` # do not change
suffix=".html"

# who should be notified? eg. "foo@bar.de spam@eggs.com"
mailto="foo@bar.de"

mailContent=""

for i in $(seq 0 $lastIndex); do
    date=`date`
    file=${files[$i]}
    address=${addresses[$i]}
    checksum="0"
    if [ -f $cwd$file$suffix ]; then
	checksum=`md5sum $cwd$file$suffix` &&
	    rm $cwd$file$suffix
    fi
    wget -o /dev/null --output-document=$cwd$file$suffix $address &&
	newchecksum=`md5sum $cwd$file$suffix` &&
	if [ "$newchecksum" = "$checksum" ]; then
	    echo $date $file  "nothing updated"
	elif [ "$checksum" = "0" ]; then
	    echo $date $file$suffix " created"
	else
	    echo $date $file "has changed"
	    mailContent=$mailContent$date" "$file"( "$address" ) has changed \n\n"
	fi
done

if [ "$mailContent" != "" ]; then
    for recipient in $mailto; do
	echo -e $mailContent|mutt -s "[HP Updates]" $recipient && echo "mail to "$recipient" successfully sent"
    done
fi