#!/bin/bash
# export http_proxy=http://wr-linux01.rki.ivbb.bund.de:3128/
# export http_proxy=http://wittenau.ivbb.bund.de:80/
source /etc/local/profile.local > /dev/null

touch ~/tmp/mn-links.new
touch ~/tmp/mn-links.old
[ -s ~/tmp/mn-links.old ] && cp -a ~/tmp/mn-links.old ~/tmp/mn-links.old2
[ -s ~/tmp/mn-links.new ] && mv ~/tmp/mn-links.new ~/tmp/mn-links.old

lynx -dump http://linuxmednews.com/ | \
     grep http.*linuxmednews.com/linuxmednews/[0-9]*/index_html | \
     cut -c 7- >  ~/tmp/mn-links.new

# echo start1

cat ~/tmp/mn-links.new ~/tmp/mn-links.old ~/tmp/mn-links.old ~/tmp/mn-links.old2 ~/tmp/mn-links.old2 |sort|uniq -u|while read a
do
	#echo $a
	w3m -dump_source "$a"| ~/bin/mednews.pl > /tmp/mn_$$.html
	#echo 1
	w3m -dump /tmp/mn_$$.html > /tmp/mn_$$_.html
	#echo 2
	(echo $a; echo ; cat /tmp/mn_$$_.html)| mail -s "MN: `head -1 /tmp/mn_$$_.html`" tillea@localhost
	#echo 3
	rm /tmp/mn_$$.html /tmp/mn_$$_.html
	#echo 4
done
