Created
July 22, 2013 08:48
-
-
Save svenk/6052360 to your computer and use it in GitHub Desktop.
A website change checker / detection changer / script to keep track of changes of any website (URL). Intended to be run on a 24/7 running server like a login server in your university institute.
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 | |
# | |
# Notify when website changes-script: | |
# This is a simple mini program that informs you whenever a website | |
# changes. Can perform any job when triggered. | |
# Usage: | |
# ./notify "jobname fuer mail" "http://abc.def/interessant.html" | |
# The script will run "in foregrund". You can e.g. use GNU screen to detach it | |
# and run it in the background on a 24h-running-server: | |
# $ screen | |
# $ ./notify ... | |
# => now press CRTL (STRG in german) + a + d <= | |
# [detached from 2850.pts-0.phoebe] | |
# $ | |
# => if you want your screen session back: <= | |
# $ screen -r | |
# => same CRTL + a + d as above <= | |
# read `man screen` for further instructions. | |
# | |
# Written just for fun by Sven, 2011 | |
# (Actually written to be notified when exam grades are online) | |
# Public Domain | |
job="$1" | |
url="$2" | |
additional_mailto="$3" | |
mailto="my-email-adress@example.com" | |
delay=5m | |
notify_delays=876 | |
new_file=`mktemp` | |
old_file=`mktemp` | |
dealys_elapsed=0 | |
get() { | |
wget -qO$1 $url | |
} | |
final_sendmail() { | |
mailto="$mailto $additional_mailto" | |
sendmail "$1" "$2" "$3" | |
} | |
sendmail() { | |
# usage: sendmail "title" "text" [file to attach] | |
text=`mktemp` | |
cat > $text << EOF | |
Website notify script auf $(hostname) um $(date -R). | |
Jobname: $job | |
Beobachtete URL: $url | |
Nachricht: $2 | |
EOF | |
[[ $3 ]] && cat $3 >> $text | |
cat $text | mail -s "$job Website notify - $1" $mailto | |
rm $text | |
} | |
# initial | |
get $old_file | |
echo "Type 'rm $old_file' to stop this program checking for updates" | |
while [ -f $old_file ]; | |
do get $new_file; | |
diffout=$(mktemp) | |
diff $old_file $new_file > $diffout | |
if [ $? != 0 ]; then | |
echo "URL content changed!" | |
# play a sound: mpg123 /your/music.mp3 | |
# popup a window: xmessage "$job was updated" | |
# nicer window: | |
# zenity --info --text="$job was updated" | |
# send a mail: | |
final_sendmail "AKTUALISIERT" "Website wurde aktualisiert!" $diffout | |
else | |
delays_elapsed=$[ $delays_elapsed + 1 ] | |
if [[ $delays_elapsed == $notify_delays ]]; then | |
# notify that I'm still living | |
echo Notify living | |
sendmail "notify" "Program waiting ($delay x $notify_delays)" | |
delays_elapsed=0 | |
fi | |
fi | |
rm $diffout | |
mv $new_file $old_file | |
sleep $delay | |
done; | |
echo "program quit since $old_file was deleted" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment