Friday, 30 January 2015

Shell script to load the data into staging table


#!/bin/sh
#*******************************************************************************#
#  VERSION              : @(#)$Revision: 1.0 $
#
#  DATE                 : @(#)$Date: Thursday, sep 28, 2004 2:24:2 $
#
#  DESCRIPTION          : This is Generic to Load data into staging table
#                         This can be used for all the conversion
#                         Its supports all type of valid Extension Like .csv,.dat,.txt
#
#  PARAMETERS           : 1 - File Name with Extension
#                         2 - Control File Name Without Extension
#
#  MODIFICATION HISTORY :
#    Name               Date         Ver    Description
#    ------------------ -----------  --- --------------------------------------
#    Prasad/Ranjit      30-JAN-2015  1.0    File Creation
#
#******************************************************************************

#pi=$1
#echo $pi
DB_LOGIN=$1
DATFILE1=$5
DATFILE=`echo $DATFILE1 | cut -f1 -d'.'`
EXTN=`echo $DATFILE1 | cut -f2 -d'.' | cut -f1 -d'"'`
CTLFILE=$6
SQLLDR=sqlldr

#
# Collect parameters
#
# the file we're going to SQL*Load
# Data file
#DATFILE=$2
# CTL file to SQL*Load
#CTLFILE=$3

#echo  $CTLFILE $DATFILE


# Set subdirectories
CTLDIR=$XCONV_TOP/bin
#DATDIR=$XBOL_TOP/bin
DATDIR=$XCONV_TOP/datafile/infile
ARCHIVEDIR=$XCONV_TOP/datafile/archive
LOGDIR=$XCONV_TOP/datafile/logfile
BADDIR=$XCONV_TOP/datafile/badfile
#echo $FILEID
echo $CTLFILE
echo $DATFILE1

# Set loader files
LOG=$LOGDIR/${DATFILE}`date +%d%m%Y%H%M%S`.log
BAD=$BADDIR/${DATFILE}`date +%d%m%Y%H%M%S`.bad
DATA=$DATDIR/${DATFILE}.${EXTN}
CTL=$CTLDIR/${CTLFILE}.ctl
#DATA=${DATAFILE}.csv

echo $LOG
echo $BAD
echo $DATA
echo $CTL

# Archive the datafile post load to the archive directory
cp $DATA $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc
echo copied the datafile for archiving to $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc

$SQLLDR userid=$DB_LOGIN control=$CTL  log=$LOG bad=$BAD data=$DATA errors=10000
RESULT=$?

count=`cat $LOG | grep "successfully loaded" | cut -dR -f1`

# Cat the log and bad file if there was an error.
if [ "$RESULT" != "0" ] ; then
  cat $LOG

  if [ -f $BAD ] ; then
    cat $BAD
  fi
#  if [ "$count" != "0" ] ; then
#    exit 225  
#  fi
# Otherwise extract the counts from the
else
count=`cat $LOG | grep "successfully loaded" | cut -dR -f1`
echo "$count Records are loaded"
exit $RESULT
fi

# Archive the datafile post load to the archive directory
#mv $DATA $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc
#echo moved the datafile for archiving to $ARCHIVEDIR/${DATFILE}`date +%d%m%Y%H%M%S`.arc

# Return SQL Load result

# exit $RESULT

No comments:

Post a Comment