#!/bin/sh
TDIR=/tmp
FILEx=$HOME/bin/anleihen
FILE1=$HOME/terminx-`date +%d-%m-%y`.txt
FILE3=$HOME/lynx_bookmarks.html
FILE4=$HOME/bin/zinsperp.txt
LOCK=$HOME/.lock
if [ $# -gt 0 ]; then
	echo "usage: "`basename $0`
	exit 1
fi
if [ -e $LOCK ]; then
	echo locked.
else
	cd $TDIR
	an.sh $FILEx o > $FILE1
	chmod 700 $FILE1
	$FILE1
	for a in `awk '{print $1}' $FILEx`
	do
		grep Zinstermin $a.o | awk '{ORS=" "; print $3}' > $FILE1
		KUPON=`grep Kupon $a.o | grep % | awk '{print $2"%"}'`
		if [ `grep -c $a $FILE4` -gt 0 ]; then
			grep $a $FILE4 | sed 's/\./,/g' | \
			awk '{ORS=" ";print $NF}' >> $FILE1
		else
			echo $KUPON | sed 's/\./,/g' | \
			awk '{ORS=" ";print $1}' >> $FILE1
		fi
		if  [ `grep -c $a $FILE3` = 1 ]; then
			getname.sh $a >> $FILE1
			echo "" >> $FILE1
		fi
		echo -n $a" "
		cat $FILE1
		rm $FILE1
		rm $a.o
	done
fi
