From 1629fcd4e3ada3b74b47daefc4579315b38cfd55 Mon Sep 17 00:00:00 2001 From: Alexander Weinhold Date: Sat, 28 Jan 2017 22:32:58 +0100 Subject: [PATCH] add hpUpdateNotify (checks for changes in websites) --- hpUpdateNotify | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 hpUpdateNotify diff --git a/hpUpdateNotify b/hpUpdateNotify new file mode 100644 index 0000000..f7f601c --- /dev/null +++ b/hpUpdateNotify @@ -0,0 +1,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