amountofurls=$(php getAmountOfUrls.php)

echo Andmebaasis leidub urle: 
echo $amountofurls
if(($amountofurls == 0)); then
	echo "Andmebaasis ei leidu roomamata url-e"
	exit 0;
fi

echo Sisestatud threadide arv: 
threads=$1
echo $threads

perThread=$(($amountofurls / $threads))

i=1
j=0
while(($i < $threads + 2 && $j < $amountofurls)); do
	echo "Käivitan Threadi: $i"

	start=$j;
	lopp=$(($j+$perThread));
	if (($i==$threads+1)); then
		let lopp=$amountofurls;
	fi
	let j+=$perThread;
	echo "algus $start"
	echo "lapp $lopp"
	amount=$(($lopp-$start))
	echo "limit $start, $amount"
	let i++
	php CrawlDatabaseUrls.php $start $lopp &
done


