Skip to content

Instantly share code, notes, and snippets.

@dvoiss
Created April 16, 2012 11:01
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 dvoiss/2397768 to your computer and use it in GitHub Desktop.
Save dvoiss/2397768 to your computer and use it in GitHub Desktop.
Run this script specifying a URL. The script will check the URL every 60 seconds to see if the contents change. If the contents change the script will beep and will continue until aborted.
function check_site()
{
local stored_hash=''
local changed=false
while sleep 60; do
# beep a bunch of times:
if $changed; then
if [[ "$(command -v osascript)" ]]; then
osascript -e "beep 5"
elif [[ "$(command -v tput)" ]]; then
tput bel
else
echo "IT CHANGED!"
fi
continue;
fi
local temp_hash=`curl --silent "$1" | md5`
# if stored_hash isn't set, then set it,
# otherwise check if stored_hash = temp_hash,
# if they aren't equal, beep to let me know
if [[ -z "$stored_hash" ]]; then
stored_hash=$temp_hash;
elif [[ ! "$temp_hash" = "$stored_hash" ]]; then
changed=true
fi
done
}
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then
echo
echo "Usage: $0 [url-to-check]"
echo
echo -e "Run this script specifying a URL as the only argument," \
"\nthe script will check the URL and take a hash of the html" \
"\ncontents at the URL. The script will check this every 60" \
"\nseconds to see if the contents change. If the contents" \
"\nchange the script will beep to alert you."
exit 0
fi
check_site "$1";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment