Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Created May 27, 2014 15:33
Show Gist options
  • Save Profpatsch/675e95243fdf064c4f3c to your computer and use it in GitHub Desktop.
Save Profpatsch/675e95243fdf064c4f3c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Takes recipient as first and URL to watch as second argument.
# Will create a file in the folderto compare the last state
# with the current one.
RECIPIENT=$1
URL=$2
FILENAME=$(echo "$URL" | sed -e 's,/,*,g')
if [ ! -e "$FILENAME" ]; then
curl "$URL" > "$FILENAME"
fi
curl "$URL" > "$FILENAME.new"
DIFF=$(diff -u "$FILENAME" "$FILENAME.new")
[ $? -ne 0 ] && echo sent && \
sendmail -t <<EOF
To: $RECIPIENT
From: url-watcher
Subject: $URL has changed.
"$DIFF"
EOF
mv "$FILENAME.new" "$FILENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment