#!/bin/bash # Sends an email when a webpage has been changed. # Meant to be run with cron. Body of email is url. ADDRESS="your@address.com" TMPFILE=~/bin/.urlalert [ "$1" ] || { echo " use: $(basename $0) url [subject of email]" exit } PAGE=$1 shift SUBJECT="${*:-urlalert: page has changes}" GET=$(curl -s -I "$PAGE" | awk -v p="$PAGE" ' /Last-Modified/{sub(/^[^:]*: /,"",$0);x=$0} /Content-Length/{y=$2} END{ if( x ){ print p " " x }else print p " " y } ') OLD=$(awk -v a="$PAGE" '$1 == a {print $0}' $TMPFILE 2>/dev/null) [ "$OLD" == "$GET" ] && exit echo "$PAGE" | mail -s "$SUBJECT" $ADDRESS awk -v a="$PAGE" -v g="$GET" ' $1 != a {print $0} END { print g } ' $TMPFILE 2>/dev/null > $TMPFILE.swp mv $TMPFILE.swp $TMPFILE