Skip to content

Instantly share code, notes, and snippets.

@crmne
Created July 13, 2010 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crmne/473962 to your computer and use it in GitHub Desktop.
Save crmne/473962 to your computer and use it in GitHub Desktop.
Notify if a page changes
#!/usr/bin/env sh
# This script notifies when a page changes.
# The first argument is the url, the other is a command that will notify you,
# like 'growlnotify -s -p 2 -t "Title" -m "Message"' if you use Growl.
#
# Example:
# $ notify_page_changes.sh 'http://reddit.com' 'growlnotify -s -p 2 -t "Reddit.com" -m "Changed"'
#
# IMPORTANT: remember to put your arguments in quotation marks!
INTERVAL=15
URL="$1"
NOTIFICATION="$2"
FILES=("/tmp/npc_$$_old.html" "/tmp/npc_$$_new.html")
LOGFILE="/tmp/npc_$$.log"
function download () {
curl -L -o ${FILES[1]} $URL &> $LOGFILE
if [ $? != 0 ]
then cat $LOGFILE
exit $?
fi
}
function old_is_equal_to_new () {
mv ${FILES[1]} ${FILES[0]}
download
diff -u ${FILES[0]} ${FILES[1]}
return $?
}
function clean () {
rm ${FILES[0]} ${FILES[1]} $LOGFILE
exit 0
}
trap clean INT
download
while old_is_equal_to_new; do
sleep $INTERVAL
done
eval $NOTIFICATION
clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment