#!/bin/sh 
# Copyright (C) Enzo Michelangeli 2006 -- hereby put in the public 
domain 

WWWATCHDOG_DIR='/tmp/wwwatchdog' 

RECIPIENTS="$1" 
NICK="$2" 
MONITORED_PAGE="$3" 

OLDIMAGE="$WWWATCHDOG_DIR/$NICK" 
NEWIMAGE="$OLDIMAGE.new" 
DIFF="$OLDIMAGE.diff" 

mkdir -p "$WWWATCHDOG_DIR" 
# Note: use "links": "lynx" is untested in this context 
links -dump "$MONITORED_PAGE" >"$NEWIMAGE" 
if [ -e "$OLDIMAGE" -a -e "$NEWIMAGE" ]; then 
       diff -y -W 160 --suppress-common-lines "$OLDIMAGE" "$NEWIMAGE" \ 
       | egrep ' free .*[0-9]|[0-9].* free ' \ 
       | sed -e 's/[|][^a-z]*/|-->/;s/$/|/' | tr '|' '\n' >"$DIFF" 
       if [ -s "$DIFF" ]; then 
                 (  echo "$MONITORED_PAGE has changed! Differences:" 
                   echo 
                   cat "$DIFF" 
                ) | mail -s \ 
                 "Detected change in page \"$NICK\" at $MONITORED_PAGE" 
\ 
                $RECIPIENTS 
       fi 
fi 
mv "$NEWIMAGE" "$OLDIMAGE" 
rm -f "$DIFF"
