Created
July 13, 2010 14:38
-
-
Save crmne/473962 to your computer and use it in GitHub Desktop.
Notify if a page changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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