#!/usr/bin/ksh
#
# epo_ucla_rmd_mirror_batch.ksh - Calls the main mirror script for
# each of the EPO sites
#
#
# Creation Date:
#
#               22 April 2008 TimQuinn
#Modified to direct output to qa location to test gaia migration Sep 2011

#
## Set the environment variables
#
  if [[ -z $THMSOC ]]
	then
	  THMSOC=/disks/socware/thmsoc_dp_current
	  export THMSOC
	fi
	#. ${THMSOC}/src/config/soc_it_to_me.config
	. /home/thmsoc/gaia2_test/soc_it_to_me.config
	
#
## Determine dates to check
#
	thisYear=$(date -u '+%Y')
	thisMonth=$(date -u '+%m')
	integer ithisMonth=$thisMonth
	integer ilastMonth=$(( ithisMonth - 1 ))
	if (( $ilastMonth <= 0 ))
	then
		lastMonth=12
		lastYear=$(( $thisYear - 1 ))
	else
		lastYear=$thisYear
		lastMonth=$(echo $ilastMonth | awk '{printf("%02d",$1)}')
	fi
	thisYearMonth=${thisYear}_${thisMonth}
	lastYearMonth=${lastYear}_${lastMonth}

#
## Step through dates/schools
#
	for yearMonth in $thisYearMonth $lastYearMonth
	do
		year=$(echo $yearMonth | awk -F_ '{print $1}')
		month=$(echo $yearMonth | awk -F_ '{print $2}')

		while read school
		do
			#epo_ucla_rmd_mirror.ksh $school $year $month
			/home/thmsoc/gaia2_test/epo_ucla_rmd_mirror.ksh $school $year $month
		done < ${CONFIGDIR}/lc_site_list_ucla_epo_fullname.txt

	done

#
## Cleanup
#
	exit 0
