#!/bin/bash
path=$(dirname "$0")
cd $path
if [ -f pid ] ; then 
	CHILDREN=$(pgrep -P $(cat pid))
	GRAN_CHILDREN=$( for p in $CHILDREN ; do pgrep -P $p ; done)
	kill $(cat pid) $CHILDREN $GRAN_CHILDREN
fi
echo $$ > pid
for dir in *.dir ; do 
	site=$(basename $dir .dir)
	if [ ! -p fifo.$site ] ; then
        	mkfifo fifo.$site
        	resfifo=$?
        	if [ $resfifo -ne 0 ] ; then
			exit 1
        	fi
	fi
	echo -n starting $path/scan_dirs.sh "$site"...
	$path/scan_dirs.sh "$site" >> $site.log 2>&1 &
	echo OK
	echo -n waiting... 
	sleep 0.5
	echo OK
	echo -n starting $path/scan_fifo.sh "$site"...
	$path/scan_fifo.sh "$site" >> $site.log 2>&1 &
	echo OK
done
wait

