Skip to content

Instantly share code, notes, and snippets.

@phil-lopreiato
Created September 29, 2014 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phil-lopreiato/ffcd634af2efe3a5181a to your computer and use it in GitHub Desktop.
Save phil-lopreiato/ffcd634af2efe3a5181a to your computer and use it in GitHub Desktop.
A script for checking when websites have changed and notifying via email
#!/bin/bash
CHANGED=()
abs=/abs/path/to/script/
# if we're calling from cronjob, use absolute path
if [ "$abs" == $(pwd) ]; then
pref=
else
pref=$abs
fi
sites=$pref
sites+="sites.txt"
while read url; do
file=$pref
file+="."`echo $url | md5sum | cut -f1 -d" "`
if [ ! -f $file ]; then
last=
else
last=$(cat $file)
fi
wget $url -O $file
current=$(cat $file)
if [ "$last" != "$current" ]; then
CHANGED+=($url)
fi
done < $sites
if [ ${#CHANGED[@]} -gt 0 ]; then
# We need to send an email out
efile=$pref
efile+="emails.txt"
emails=$(sed 's/#.*$//g' < "$efile") # remove comments
emails=$(echo $emails | tr ' ' ',') # Make comma separated list
msg="The following websites have changed since yesterday. You should check them out.\n"
for i in "${CHANGED[@]}"; do
msg+="$i \n"
done
msg+="Thanks,\nHades"
echo -e $msg | mail -s "Class Updates" user -b $emails -- -F"Class Update Bot" -ffrom@email.com
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment