| verzia 1.1, 2002/02/01 22:52:46 |
verzia 1.2, 2002/02/02 01:15:15 |
|
|
| |
|
| # Script for watching changes on some websites |
# Script for watching changes on some websites |
| |
|
| # File with remembered state of website |
|
| file="./last" |
|
| web=$1 |
|
| |
|
| # This script send mail to user which run this script |
# This script send mail to user which run this script |
| mailto="`id -nu`" |
mailto="`id -nu`" |
| |
|
| if [ $# -lt 1 ]; then |
# URL for watching: |
| echo "Usage: $0 <http_adress>"; |
CONFIG="$HOME/.wwwdiffrc" |
| exit; |
USER_DIR="$HOME/.wwwdiff" |
| |
|
| |
MSG="These websites was modified: |
| |
---" |
| |
|
| |
# if no config file found |
| |
if [ ! -f $CONFIG ]; then |
| |
exit |
| fi |
fi |
| |
|
| if [ -f $file ]; then |
# Empty lines or comments are ignored in configfile |
| wget -O - $web 2>/dev/null | diff - $file ; |
LINES="`cat -n $CONFIG | \ |
| if [ $? == 0 ]; then # no change found |
egrep -v '^[ ]*([[:digit:]]*)([ ]*)[#;"]' | \ |
| echo "No change found, exiting"; |
egrep -v '^[ ]*([[:digit:]]*)([ ]*)$' | \ |
| exit; |
awk '{ print $1}' `" |
| elif [ $? == 1 ]; then # some change found |
|
| echo -en "Sending mail..."; |
for i in $LINES |
| echo "Website $web is modified, please check it..." | mail $mailto ; |
do |
| echo "done." |
web=`awk "{ if (NR == $i) print }" $CONFIG ` |
| exit; |
# Substituing special characters: / ? ; & | $ ! * |
| |
ACTUAL_STATE=`echo $web | \ |
| |
sed 's|[/\?\;&\|\$\!\*"]|_|g; s|\.\.|--|g;'` |
| |
web_file="$USER_DIR/$ACTUAL_STATE" |
| |
|
| |
if [ -f $web_file ]; then |
| |
wget -O - $web 2>/dev/null | diff - $web_file 1>/dev/null; |
| |
if [ $? = 1 ]; then # some change found |
| |
MSG="$MSG |
| |
$web" |
| |
fi |
| |
else # file $web_file not found |
| |
# echo "File $web_file doesn't exist, getting it and exiting..."; |
| |
if [ ! -d $USER_DIR ]; then |
| |
mkdir -p "$USER_DIR" |
| |
fi |
| |
wget -O - $web > $web_file 2>/dev/null; |
| |
if [ $? = 0 ]; then |
| |
echo "Saving $web" |
| |
fi |
| fi |
fi |
| else # file $file not found |
done |
| echo "File $file doesn't exist, getting it and exiting..."; |
MSG="$MSG |
| wget -O - $web > $file 2>/dev/null; |
---" |
| exit; |
|
| fi |
echo "$MSG" #| mail -s '[WWWdiff]' $mailto |
| |
|
| |
|