Skip to content

Instantly share code, notes, and snippets.

@maxme
Last active June 6, 2023 18:28
Show Gist options
  • Save maxme/c31ffbb3cb21f3baa6e9c9e61bbe0a72 to your computer and use it in GitHub Desktop.
Save maxme/c31ffbb3cb21f3baa6e9c9e61bbe0a72 to your computer and use it in GitHub Desktop.
Set this up in a crontab to check if a webpage changed since last check. It will email you the diff when it happens.
#!/bin/sh
checkIfPageChanged() {
URL="$1"
EMAIL_ADDRESS="$2"
CSS_SELECTOR="$3"
SILENT="$4"
tmpfile1=/tmp/$(echo $URL| sha1sum | cut -d" " -f1)
tmpfile2=$tmpfile1-1
curl -L --silent "$URL" -A "Maxme/1.0 (Watching for changes; https://gist.github.com/maxme/c31ffbb3cb21f3baa6e9c9e61bbe0a72)" \
| hxclean 2> /dev/null \
| hxselect "$CSS_SELECTOR" > $tmpfile1 2> /dev/null
diff $tmpfile2 $tmpfile1 > /dev/null 2> /dev/null
if [ $? -eq 1 ]; then
if [ x"$SILENT" = x ]; then
echo "$URL was modified since last check"
fi
diff -u $tmpfile2 $tmpfile1 | mail -s "[modified web page] $URL" "$EMAIL_ADDRESS"
fi
mv $tmpfile1 $tmpfile2
}
if [ x"$3" = x ]; then
echo "Usage: $0 URL EMAIL_ADDRESS SLEEP_TIME_SEC CSS_SELECTOR [silent]"
echo "Example: $0 https://github.com/maxme/bitcoin-arbitrage/pulls [email protected] .issues-listing"
exit 1
fi
checkIfPageChanged "$1" "$2" "$3" "$4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment