Monitoring¶
Sometimes you just want to see if a webpage changed. A simple one. No RSS available and you know that writing to the one running it and asking for RSS would go probably beyond his/her capacities. Sometimes it doesn’t even make sense.
So what to do?
This little script in Cron will now check a website and send me a mail when it detects a change. It isn’t pretty, but it works.
#!/bin/bash
# Checking for changes of a webpage
USERNAME="emailuser"
PASSWORD="emailpw"
URL="http://URL/I/WANT/TO/CHECK"
#for (( ; ; )); do
mv new.html old.html 2> /dev/null
curl $URL -L --compressed -s > new.html
DIFF_OUTPUT="$(diff new.html old.html)"
if [ "0" != "${#DIFF_OUTPUT}" ]; then
sendEmail -f $USERNAME -s smtp.example.com:25 \
-xu $USERNAME -xp $PASSWORD -t $USERNAME \
-o tls=yes -u "Web page changed" \
-m "Visit it at $URL"
# sleep 10
fi
#done
The commented lines will run the script in a loop with a pause of 10 seconds. I don’t need an email right away, so I put the script in cron instead.