Last active
June 7, 2018 13:56
-
-
Save Wikinaut/1a1810efb8dd07a6ce823d5366c26407 to your computer and use it in GitHub Desktop.
pagewatcher.sh - MySimplePageWatcher - Watch a webpage for 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 | |
# Page watcher Cronscript | |
# initial 201804xx | |
if [ $# -lt 1 ] ; then | |
echo "pagewatcher watches an url and sends an e-mail in case of changes." | |
echo | |
echo "usage: pagewatcher.sh url [additional-mail-recipients] | clean" | |
echo | |
exit | |
fi | |
if [ $1 = "clean" ]; then | |
rm /tmp/pagewatch-* | |
exit | |
fi | |
url=$1 | |
sendmailonfirstrun="false" | |
mailto="root" | |
if [ "$2" != "" ]; then | |
mailto="root,$2" | |
fi | |
md5=$(echo -n "$url" | md5sum | awk '{ print $1 }') | |
page="/tmp/pagewatch-${md5}" | |
pagelast="${page}.last" | |
diff="${page}.diff" | |
mail="/usr/bin/mail" | |
wget $url -O "${page}" &> /dev/null | |
if [ ! -f "${pagelast}" ]; then | |
if [ $sendmailonfirstrun = "true" ]; then | |
touch "${pagelast}" | |
else | |
cp "${page}" "${pagelast}" | |
fi | |
fi | |
if [ -s "${page}" ]; then | |
# Are there differences to the last run? | |
diff -q "${pagelast}" "${page}" > /dev/null 2>&1 | |
if [ $? -ne 0 ] ; then | |
echo -e "$url has changed.\n" > "${diff}" | |
diff --suppress-common-lines -u0 "${pagelast}" "${page}" >> "${diff}" 2>&1 | |
$mail -s "$url has changed." $mailto < "${diff}" | |
cp "${page}" "${pagelast}" | |
rm "${diff}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment