Created
September 29, 2014 16:20
-
-
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
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 | |
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