Skip to content

Instantly share code, notes, and snippets.

@Lucas-C
Last active September 19, 2017 11:32
Show Gist options
  • Save Lucas-C/38d4070a34af13df2b8bb21bea5561e1 to your computer and use it in GitHub Desktop.
Save Lucas-C/38d4070a34af13df2b8bb21bea5561e1 to your computer and use it in GitHub Desktop.
Bash script to use in a cron job in order to receive an email when a web page changes
#!/bin/bash
# USAGE: ./webpage_modification_notifier.sh $URL
set -o pipefail -o errexit -o nounset
date
cd $(dirname "${BASH_SOURCE[0]}")
url="${1?'Argument required'}"
echo $url
last_version=${url//[^[:alpha:]]/}.html
tmpfile=$(mktemp /tmp/webpage_modification_notifier.XXXXXX)
curl -sk "$url" | grep -vE 'random|sesskey' > $tmpfile
if ! [ -e "$last_version" ]; then
mv $tmpfile $last_version
exit 0
fi
if diff -q $last_version $tmpfile; then
rm $tmpfile
exit 0
fi
echo "Web page changed, sending notification"
(echo -e "$url\n\n"; diff $last_version $tmpfile || true) | mail -s "[webpage_modification_notifier] Change detected on $url" [email protected]
mv $tmpfile $last_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment