Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm looking for a way to have a script running on my desktop that will check a certain webpage for changes every x seconds, and if a change is made, it gives me an alert. I understand that with high-end websites, some changes will be made almost constantly, but what I'm looking for monitoring now is a bare-bones HTML page that I'm waiting for a link to show up on. Is there a way to do this?

Edit: Would it be a command to download the html and store it, and then a recurring download-and-check command?

share|improve this question

closed as off topic by bmike Jan 20 '13 at 17:44

Questions on Ask Different are expected to relate to Apple hardware or software within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Would a shell script (running in Terminal) be an option as well? –  patrix Jan 14 '13 at 20:24
    
@patrix Yes, it would. –  JShoe Jan 14 '13 at 21:58
    
In case you want to try yourself, look at curl and diff (man curl and man diff in Terminal) and read any Bash shell programming tutorial. –  patrix Jan 15 '13 at 4:27
    
The part where this specifies to parse a multitude of HTML documents and programmatically determine if this constitutes a "change" would be better suited on StackOverflow.com. An edited question on how to automate the download of one URL to a file would seem to be on topic since Automator allows that functionality. –  bmike Jan 20 '13 at 17:45
add comment

1 Answer 1

Save this as ~/bin/example and run chmod +x ~/bin/example. (Edited to only check the modification date from the header.)

#!/bin/bash

url=http://www.iana.org/domains/example
tempdir=~/Library/Caches/scripts
temp=$tempdir/example
mkdir -p $tempdir
modified=$(curl -sI "$url" | grep ^Last-Modified)
if [[ -f "$temp" && "$modified" != "$(cat $temp)" ]]; then
    terminal-notifier -message 'Example changed'
fi
printf %s "$modified" > $temp

To run it every 15 minutes, add */15 * * * * ~/bin/example to crontab (EDITOR=nano crontab -e).

terminal-notifier can be installed with sudo gem install terminal-notifier.

You could also run it every five seconds in a shell window:

while :; do ~/bin/example; sleep 5; done
share|improve this answer
1  
If the server publishes an ETag or Last-Modified header, you wouldn't even need to download the whole page but only the headers reducing resource wasting on both sides. –  MacLemon Jan 15 '13 at 9:06
    
Where is "$tmp/example" fetched from the web once to act as a baseline? –  patrix Jan 15 '13 at 9:58
    
Sorry to be picky but $temp still needs to be initialized (e.g. by running curl -sI "$url" | grep ^Last-Modified > "$temp") –  patrix Jan 15 '13 at 11:25
    
@patrix I forgot that -f check from the first revisions, thanks. –  Lri Jan 15 '13 at 12:58
    
So...I don't like using code I don't understand. I'll accept this as the answer, but sometime could someone walk me through how it works in chat? –  JShoe Jan 18 '13 at 4:53
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.