HOME=/work/leverington/beamprofilemonitor/hitdata/Scripts/Scripts_20161201
mkdir -p $HOME/jobs #make the directory if it doesn't exist
JOB_HOME=$HOME/jobs 
rm -rf $JOB_HOME/* #clean up the directory if it does exist
cd $JOB_HOME
for i in {1..46}
do
    if  [ $i -gt 19 -a $i -lt 29 ]; then 
	continue
    fi
    
	touch $JOB_HOME/runjob$i.sh
	echo "#!/bin/bash" >> $JOB_HOME/runjob$i.sh
	echo ". /local/env.sh" >> $JOB_HOME/runjob$i.sh
	echo ". /cvmfs/lhcb.cern.ch/lib/lhcb/LBSCRIPTS/LBSCRIPTS_v9r2p2/InstallArea/scripts/LbLogin.sh -c x86_64-slc6-gcc49-opt" >> $JOB_HOME/runjob$i.sh
#	echo ". SetupProject.sh Geant4" >> $JOB_HOME/runjob$i.sh

	echo "source /cvmfs/lhcb.cern.ch/lib/lcg/releases/gcc/4.9.3/x86_64-slc6/setup.sh" >> $JOB_HOME/runjob$i.sh
        #point to the correct CERN ROOT 
	echo "source /cvmfs/lhcb.cern.ch/lib/lcg/releases/LCG_84/ROOT/6.06.02/x86_64-slc6-gcc49-opt/bin/thisroot.sh " >> $JOB_HOME/runjob$i.sh
        #include the gsl libraries
	echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/work/leverington/gsl-2.4/lib " >> $JOB_HOME/runjob$i.sh



        #execute this command
	echo "/work/leverington/beamprofilemonitor/hitdata/Scripts/Scripts_20161201/analyse2 PiN_run$i.root" >> $JOB_HOME/runjob$i.sh

	

	qsub -l os=slc6 -l ujl=20 -cwd -j yes $JOB_HOME/runjob$i.sh
sleep 1
done
