#!/usr/local/bin/bash
. /fnal/ups/etc/setups.sh
ulimit -d unlimited -s unlimited -c 0
umask 002
echo -e "---------------------------------------------------------------"
date
echo -e "Begin setup of products needed"
setup dp 
echo -e "Done setup of products needed"
echo -e "---------------------------------------------------------------"
date
echo -e "PATH = $PATH"
echo -e "---------------------------------------------------------------"
date
printenv | grep _DIR | sort
echo -e "---------------------------------------------------------------"
echo -e "Kerberos Data: (klist -f)"
/usr/krb5/bin/klist -f
echo -e "---------------------------------------------------------------"
echo ---------------------------------------------------------------
date
if [ -f /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log ]
then
    if [ -f /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log.OLD ]
    then
      cat /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log >> /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log.OLD
      rm /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log
    else
      mv /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.log.OLD
    fi
fi
if [ -f /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err ]
then
    if [ -f /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err.OLD ]
    then
      cat /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err >> /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err.OLD
      rm /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err
    else
      mv /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err /opdb/d1/data/tileChunk/chunk109/stuffCompleteTile.err.OLD
    fi
fi
date
setup ts
echo ---------------------------------------------------------------
date
echo Begin stuffing completeTile
ts -noTk -command "stuff_completeTile chunk109 hlin" 
if [ $? -ne 0 ]
then
  echo Error: Stuffing of completeTile for chunk chunk109 failed.
  exit 1
fi
echo Done stuffing completeTile
echo ---------------------------------------------------------------
date
echo ALL DONE
exit

