#/bin/bash
cd $(dirname $0) #change directory to the diretory this file is in

while [ -f botprocessing.lock ]; do
	if [ "$(ps -p `cat botprocessing.lock` | wc -l)" -gt 1 ]; then
		echo "process is still running" >> botprocessing.log
		sleep 5
		exit
	else
		# process not running, but lock file not deleted?
		rm botprocessing.lock
	fi
done
#Create Lock
echo $$ > botprocessing.lock

date >> botprocessing.log
ruby botprocessing.rb >> botprocessing.log

echo "moving botprocessingwriting.json to botprocessing.json"
mv botprocessingwriting.json botprocessing.json

ruby bounds.rb >> bounds.log

#remove lock
rm botprocessing.lock
