#!/bin/bash

source /gpfs/wizard/flight/production/installed/set_pam_env.sh > /dev/null 2>&1;

export PRODDIR=/gpfs/wizard/flight/production/

export L2=$PRODDIR/level2/

export POSTRR=$PRODDIR/postRawreader/

export LOGDIR=$PRODDIR/logs/

export YODA_DATA=$PRODDIR/level0/

export YODA_LOGS=$PRODDIR/level0/

#export PAM_DBHOST=mysql://srv-g2-01.ts.infn.it/test
export PAM_DBHOST=mysql://srv-g2-01.ts.infn.it/pamela

export PAM_DBUSER=root

export PAM_DBPSW=Calo0%Ts

IDRUN=$1

LOG=$LOGDIR/dv.${IDRUN}.log

rm -f $LOG;

touch $LOG;

chmod g+rw $LOG;

echo "#####################################" >> $LOG 2>&1;

echo " DARTHVADER LOG FOR RUN $IDRUN " >> $LOG 2>&1;

echo "#####################################" >> $LOG 2>&1;

echo -n " Start date is: " >> $LOG 2>&1;

date >> $LOG 2>&1;

echo " Job is running on WN: "`hostname` >> $LOG 2>&1;

if [ "$PAM_BIN" == "" ]; then 
    
    echo "ERROR DURING PAM_ENV SETUP!" >> $LOG 2>&1; 

    exit; 

fi

cd $L2 >> $LOG 2>&1;

echo " Running in the directory `pwd`" >> $LOG 2>&1;

DarthVader -b -c -zerofill +ALL -idRun $IDRUN  >> $LOG 2>&1;

echo -n " End date is: " >> $LOG  2>&1;

date >> $LOG 2>&1;



