Skip to content

Instantly share code, notes, and snippets.

@brokaw
Created September 21, 2011 21:55
Show Gist options
  • Save brokaw/1233436 to your computer and use it in GitHub Desktop.
Save brokaw/1233436 to your computer and use it in GitHub Desktop.
Monitor the Last-Modified HTTP header on www.aclfestival.com. Designed for Mac OS X.
#!/bin/bash
# $1 = recipient
# $2 = The Subject
# $3 = The message content
sendapplemail() {
/usr/bin/osascript >/dev/null 2>&1 <<EOF
tell application "Mail"
set myContent to quoted form of "$3"
set theMessage to make new outgoing message with properties {subject:"$2", content:myContent, sender:"Steve Brokaw <steve@jetseven.org>"}
tell theMessage
make new to recipient at end of to recipients with properties {address:"$1"}
end tell
set theResult to send theMessage
end tell
EOF
}
updatetime() {
curl -A 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201' -sI http://www.aclfestival.com | sed -n 's/^Last-Modified\:\ \(.*$\)/\1/p'
}
LAST_UPDATED=$(updatetime)
echo -n "Starting to check at: "
date -u
echo "Last updated: ${LAST_UPDATED}"
PREVIOUS_UPDATE=$LAST_UPDATED
while true
do
if [[ $PREVIOUS_UPDATE != $LAST_UPDATED ]]
then
echo "^GChange Detected: $LAST_UPDATED"
say "ACL website change detected" &
PREVIOUS_UPDATE=$LAST_UPDATED
CONTENT=$(curl -s http://www.aclfestival.com | grep -C 2 Souvenir | sed 's/\"//g')
if [[ ! $CONTENT =~ "Coming Soon" ]]
then
sendapplemail "##########@txt.att.net" "ACL HIGH ALERT!" "Check www.aclfestival.com NOW!" &
sendapplemail "email@example.com" "ALERT aclfestival.com was updated $LAST_UPDATED" "$CONTENT" &
else
sendapplemail "email@example.com" "aclfestival.com was updated $LAST_UPDATED" "$CONTENT" &
fi
fi
sleep 60
LAST_UPDATED=$(updatetime)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment