a bteq shell wrapper

# bteqshellwrapper.ksh

 

USAGE_pet_bteq(){
cat << EOI
#USAGE: bteqshellwrapper.ksh SQLFILE
#PARAMETER:
#          1. SQLFILE - the sql file name to be executed by bteq, without path.
EOI
}

if [ $# -ne 1 ]
then
 USAGE_pet_bteq
    exit 1
fi

if [ -f "$HOME"'/bin/var.setup' ]
then
 . "$HOME"'/bin/var.setup'
fi

SQLFILE="${SQLROOT}"'/'"$1"
if [ ! -f ${SQLFILE} ]
then
 echo "SQL File doesn't exist: ""${SQLFILE}"
    exit 2 
fi

SQLFILE="${SQLROOT}"'/'"$1"

RUN_SQL_TMP_FILE="${TMPROOT}"'/'"$1"'.tmp'
echo "cat <<EOF" > ${RUN_SQL_TMP_FILE}
cat ${SQLFILE} >> ${RUN_SQL_TMP_FILE}
echo "/nEOF" >> ${RUN_SQL_TMP_FILE}

. ${RUN_SQL_TMP_FILE} > "${RUN_SQL_TMP_FILE}"'.2'
mv "${RUN_SQL_TMP_FILE}"'.2' ${RUN_SQL_TMP_FILE}

RUN_SQL_LOGFILE="${LOGROOT}"'/'"$1"'.'`date +"%y%m%d%H%M%S"`'.log'

 


echo "########BEGIN INVOKING BTEQ########"
set +e
bteq <<EOF | tee ${RUN_SQL_LOGFILE}
.SET ERROROUT STDOUT
.set session transaction btet
.logon ${TDP}/${TD_USERNAME},${TD_PASSWORD}
select 'SESS', session;
.maxerror 1
.run file=${RUN_SQL_TMP_FILE};
EOF
rcode=$?
set -e


if [ rcode -ne 0 ]
then
    echo "Error executing SQL:"
    echo
    #Log File ...
    #cat ${RUN_SQL_LOGFILE}
    exit 3
fi

echo "########END INVOKING BTEQ########"
exit 0

你可能感兴趣的:(sql,Date,shell,session,File,wrapper)