#!/usr/bin/ksh
#
# This script writes lists UAtha rmd files to database. It is intended to be used when for some 
# reason the automatic daily write of file names to the database has failed. 
#

## 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  
. $THMSOC/src/config/gbo_atha_rmd_mirror.config


for school in VLDR
do
  while read path
  do
    fileName=${path##*/}
    schName=$(echo $fileName |awk -F_ '{print substr($1,1,4)}')
    year=$(echo $fileName | awk -F_ '{print "20"substr($1,5,2)}')
    month=$(echo $fileName | awk -F_ '{print substr($1,7,2)}')
    day=$(echo $fileName | awk -F_ '{print substr($1,9,2)}')
    hr=$(echo $fileName | awk -F_ '{print $3}')
    mn=$(echo $fileName | awk -F_ '{print substr($4,1,2)}')
    dataTime="${year}-${month}-${day} ${hr}:${mn}:00" 
    mysql_table_name=gbo_${schName}_rmdfiles
    fileSize=$(ls -l ${ATHA_MIRROR_HOME}/${school}/${year}/${month}/${day}/$fileName |awk '{print $5}')
    processTime=$(date -u '+%Y-%m-%d %T')
    processCode="HardDrive"
echo $fileName
echo $mysql_table_name

    echo "$mysql_table_name $dataTime $fileName $processTime $processCode $fileSize"
    ${PHP_SCRIPTS}/gbo_uatha_rmd_mirror.php $mysql_table_name \
    				$dataTime $fileName $processTime $processCode $fileSize
 done < /home/thmsoc/lphilpotts_stuff/filelists/${school}_rmd_files
done

exit 0