Last active
January 18, 2019 09:11
-
-
Save maxme/b153bab5c4b8e7c3ab6eeabc74d7a00c to your computer and use it in GitHub Desktop.
Watch for web page change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Require curl and html-xml-utils | |
TMPFILE1=$(mktemp) | |
TMPFILE2=$TMPFILE1-1 | |
function checkIfPageChanged() { | |
URL="$1" | |
EMAIL_ADDRESS="$2" | |
CSS_SELECTOR="$3" | |
curl --silent "$URL" -A "Maxme/1.0 (Watching for changes; https://github.com/maxme/)" \ | |
| hxclean \ | |
| hxselect "$CSS_SELECTOR" > $TMPFILE1 2> /dev/null | |
diff $TMPFILE1 $TMPFILE2 > /dev/null 2> /dev/null | |
if [ $? -eq 1 ]; then | |
# page changed, send an email | |
echo "$URL was modified since last time" | |
diff $TMPFILE2 $TMPFILE1 | mail -s "[modified web page] $URL" "$EMAIL_ADDRESS" | |
fi | |
mv $TMPFILE1 $TMPFILE2 | |
} | |
if [ x$4 == x ]; then | |
echo "Usage: $0 URL EMAIL_ADDRESS SLEEP_TIME_SEC CSS_SELECTOR" | |
echo "Example: $0 https://github.com/maxme/bitcoin-arbitrage/pulls [email protected] 3600 .issues-listing" | |
exit 1 | |
fi | |
URL=$1 | |
EMAIL_ADDRESS=$2 | |
SLEEP_TIME=$3 | |
CSS_SELECTOR=$4 | |
while True; do | |
echo "Check if $URL changed" | |
checkIfPageChanged "$URL" "$EMAIL_ADDRESS" "$CSS_SELECTOR" | |
sleep $SLEEP_TIME | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment