Monitor changes on a webpage

Say that you are waiting for some results, that will be announced of a web page some time during the day… You can spend the day hitting Ctrl-R on your navigator (to refresh the page), or you can try the script pasted below. It will check for changes on the web page every 15 minutes (you can change the timing), will stop once a change is detected, and will then open the web page so that you can see the new version.


# Monitors the changes in a webpage
# To run it:
# ./ mywebpage
# where `` is the address of the page you want to follow,
# and mywebpage a suffix (default: page), needed if you monitor multiple pages at once.
# -> The program checks the website every 15 minutes (timing can be changed),
#    and if there is a change, opens the new webpage.
# This script works with Ubuntu;
# On a Mac, replace "xdg-open" by "open"
# Source of some of the code:

# URL to monitor is entered as input
# The second argument is optional, it is a suffix for the webpage
# if we want to monitor multiple webpages at once

# Error message if not argument is supplied
if [[ -z "$*"  ]] ; then
echo "Error: you need to enter a webpage as argument!
(don't forget http://)"
exit 0

echo "Monitoring "${URL}

# Initialization: download the webpage once to create old.html
curl ${URL} -L --compressed -s > old${SUFF}.html

for (( ; ; )); do # (Infinite loop)
# Change the name of new.html into old.html,
# and erase potential error messages (2> /dev/null)
mv new${SUFF}.html old${SUFF}.html 2> /dev/null

# Print time at which the page is checked
echo "Last checked: ${THEDATE}"

# Download the webpage
curl ${URL} -L --compressed -s > new${SUFF}.html
#  -L means that we follow potential redirections
#  --compressed compresses,
#  -s for quiet mode,
#  and save the output in new.html.

# Compare the two versions
DIFF_OUTPUT="$(diff new${SUFF}.html old${SUFF}.html)"
# If there are differences:
if [ "${DIFF_OUTPUT}" != "" ]; then
# open the webpage
xdg-open ${URL}
# Then wait for 15 minutes before checking the website again
sleep 15m

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s