Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #--------------------------------------------------------------------------------
- # Monitors the changes in a webpage
- #
- # To run it:
- # ./monitorwebpage.sh http://www.thewebpage.io mywebpage
- # where `http://www.thewebpage.io` 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.
- #
- #
- #
- # NOTES:
- #
- # This script works with Ubuntu;
- # On a Mac, replace "xdg-open" by "open"
- #
- # Source of some of the code:
- # http://bhfsteve.blogspot.fr/2013/03/monitoring-web-page-for-changes-using.html
- # And this script source: https://trucastuces.wordpress.com/2017/04/21/monitor-changes-on-a-webpage/
- #--------------------------------------------------------------------------------
- # URL to monitor is entered as input
- URL="$1"
- # The second argument is optional, it is a suffix for the webpage
- # if we want to monitor multiple webpages at once
- # SUFF=${2:-page}
- # 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
- fi
- echo "Monitoring "${URL}
- chmod -R 774 /home/$USER/bin/monitorURL/work/
- chmod -R 664 /home/$USER/bin/monitorURL/work/*
- cd /home/$USER/bin/monitorURL/work/
- # Initialization: download the webpage once to create old.html
- # curl ${URL} -L --compressed -s > old${SUFF}.html
- curl ${URL} -L --compressed -s > old.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
- mv new.html old.html 2> /dev/null
- # Print time at which the page is checked
- THEDATE="$(date)"
- echo "Last checked: ${THEDATE}"
- # Download the webpage
- # curl ${URL} -L --compressed -s > new${SUFF}.html
- curl ${URL} -L --compressed -s > new.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)"
- DIFF_OUTPUT="$(diff new.html old.html)"
- # If there are differences:
- if [ "${DIFF_OUTPUT}" != "" ]; then
- # open the webpage
- URL="$1"
- xdg-open ${URL}
- break
- fi
- # Then wait for 15 minutes before checking the website again
- # Then wait for 20 seconds before checking the website again
- sleep 20s
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement