Last active
September 19, 2017 11:32
-
-
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
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/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