#!/bin/bash
# urlcontentchanges.sh
# 2010-11-29
# by Gernot WALZL
# Checks for content changes on given URLs.
URLS="http://www.gernot-walzl.at/
http://www.documentfoundation.org/download/
http://netbeans.org/downloads/index.html"
DIR="./urlcontent"
mkdir -p "$DIR"
cd "$DIR"
i=1
for URL in $URLS; do
ARR_URLS[$i]=$URL
FILE=${URL//:/_}
FILE=${FILE////_}
FILE=${FILE//\?/_}
FILE=${FILE//=/_}
FILE=${FILE//&/_}
ARR_FILES[$i]=${FILE// /_}
let "i+=1"
done
for i in $(seq ${#ARR_URLS[@]}); do
wget -nv -O ${ARR_FILES[i]}.new ${ARR_URLS[i]}
done
echo ""
echo "The content of the following URLs has changed:"
for i in $(seq ${#ARR_URLS[@]}); do
if [ -f ${ARR_FILES[i]} ]; then
if [ $(diff ${ARR_FILES[i]} ${ARR_FILES[i]}.new | wc -l) -gt 0 ]; then
echo ${ARR_URLS[i]}
mv ${ARR_FILES[i]} ${ARR_FILES[i]}.old
mv ${ARR_FILES[i]}.new ${ARR_FILES[i]}
else
rm ${ARR_FILES[i]}.new
fi
else
mv ${ARR_FILES[i]}.new ${ARR_FILES[i]}
fi
done
echo ""