Sie sind auf Seite 1von 7

#!

/usr/bin/ksh
CONFIG_DIR=${HOME}/SW/ptsv3_msg/latest/configs
SCRIPT_PATH=${HOME}/temp/test
FILE_NAME=$1
REF_VAR1=ORDER_ID
REF_VAR3=DIRECTION
REF_VAR2=OPEN_QUANTITY
 
export UDB_DB="`grep DB_SERVER ${CONFIG_DIR}/GC-server-db.cfg |awk -F"=" {'print $2'}`"
export UDB_USER="`grep DB_USER ${CONFIG_DIR}/GC-server-db.cfg |awk -F"=" {'print $2'}`"
export UDB_PASS="`grep DB_PASSWORD ${CONFIG_DIR}/GC-server-db.cfg |awk -F"=" {'print $2'}`"
 
export TRDU_DB="`grep trd.conn ${CONFIG_DIR}/GC-server-db.cfg|awk -F"=" {'print $2'}`"
export TRDU_USER="`grep trd.user ${CONFIG_DIR}/GC-server-db.cfg |awk -F"=" {'print $2'}`"
export TRDU_PASS="`grep trd.pass ${CONFIG_DIR}/GC-server-db.cfg |awk -F"=" {'print $2'}`"
 
################open_order_recon_lvts.csv Formatting############
 
 function Format_LVTS_Amount
 
   {
     `dos2unix -437 $FILE_NAME $FILE_NAME`
 
   varF=`awk -F, {'print $2'} $FILE_NAME |head -1`
   varG=`awk -F, {'print $9'} $FILE_NAME |head -1`
   varH=`awk -F, {'print $7'} $FILE_NAME |head -1`
 
    varF=`echo $varF | tr "[a-z]" "[A-Z]"`
if [ $varF != $REF_VAR1 ]; then
Error_Handling 1
Exit 1
fi

    varG=`echo $varG | tr "[a-z]" "[A-Z]"`


if [ $varG != $REF_VAR2 ]; then
Error_Handling 1
Exit 1
Fi

    varH=`echo $varH | tr "[a-z]" "[A-Z]"`


if [ $varH != $REF_VAR3 ]; then
Error_Handling 1
Exit 1
Fi
 
  echo "Formatting LVTS Data....\n"
 awk -F, {'print $2" "$9" "$7","'} $FILE_NAME | sed -e '1d' | sed -e 's/ /\,/g' | sed 's/,$//' > open_order_recon_lvts.csv
 
    varA=`wc -l $FILE_NAME | awk {'print $1'}`
    varB=`wc -l open_order_recon_lvts.csv | awk {'print $1'}`
    varB=$((varB+1))
 
  if [ $varA -ne $varB ]; then
 
       Error_Handling 9
       exit 9
  fi
 
   }
 
##############Run the query in DBPTSU###########
 
  function Get_PTS_Amount
 
 {
         clear
         echo "Feteching Data From DBPTSU...Plz be Patient"
  db2 connect reset > /dev/null
  db2 connect to ${UDB_DB} user ${UDB_USER} using ${UDB_PASS} > /dev/null
 
    if [ $? -ne 0 ] ; then
 
         Error_Handling 2
         exit 2
    fi
 
  db2 "select distinct a.ID_ORD_CLNT_SERV, e.AM_PSN , e.CD_TYP_TRAN_LVL3 from positions.allc_ord a,
positions.psn_evt e where e.ID_ORD_ALLC = a.ID_ORD_AC_PRIM = 90 and a.CD_STS_LFECYCL_CUR in
('PARTFILL','OPEN') and e.id_imnt = a.ID_IMNT and e.CD_TYP_PSN = 'O' and e.CD_RVRS = 'O' and e.ID_IMNT
not in (seference.ccy)" >query.out
 
############## Check File Size of query.out & throw exception accordingly #####

  db2 connect reset > /dev/null


 
 }
 
################open_order_recon_pts.csv Formatting###############
 
  function Format_PTS_Amount
 
 {
    echo "Formatting the PTS Data...."
    sed -e '1,3d' query.out >query.tmp1
    sed -e :a -e '$d;N;2,3ba' -e 'P;D' query.tmp1 > query.tmp
    cat query.tmp |awk {'print $1","$2","$3","'} | sed 's/,$//' >open_order_recon_pts.csv
 
    varC=`grep "record(s) selected" query.out|awk {'print $1'}`
    varD=`wc -l open_order_recon_pts.csv`
 
    if [ $varC -ne $varD ]; then
 
     Error_Handling 11
     exit 11
 
    fi
 
 }
 
##############BCP the two formatted csv files into TRD#################
 
  function BCP_in_TRD
 
 {
 
   isql -U ${TRDU_USER} -P ${TRDU_PASS} -S ${TRDU_DB} -w 500 -i $
{SCRIPT_PATH}/SQL/create_tmpDB.sql
 
   if [ $? -ne 0 ] ; then
 
           Error_Handling 3
           exit 3
   fi
 
        bcp tempdb..LVTS_open in open_order_recon_lvts.csv -SSYBUS_TRDU -UMRREPORTS -Pprintme -c -t","
 
   if [ $? -ne 0 ] ; then
 
           Error_Handling 4
           exit 4
   fi
 
        bcp tempdb..PTS_open in open_order_recon_pts.csv -SSYBUS_TRDU -UMRREPORTS -Pprintme -c -t","
 
   if [ $? -ne 0 ] ; then
 
          Error_Handling 5
          exit 5
   fi
 
 }
 
##############Update the tempdb########################
 
  function UpdateDB
 
 {
 
       isql -U ${TRDU_USER} -P ${TRDU_PASS} -S ${TRDU_DB} -w 500 -i $
{SCRIPT_PATH}/SQL/update_tmpDB.sql
 
   if [ $? -ne 0 ] ; then
 
         Error_Handling 6
         exit 6
   fi
 
 }
 
#######Run the select cmd to find the amount discrepencies#####
 
  function Chk_Amount_Mismatch
 
 {
 
     isql -U ${TRDU_USER} -P ${TRDU_PASS} -S ${TRDU_DB} -w 500 -i $
{SCRIPT_PATH}/SQL/Generate_AmountMismatch.sql >Amount_Recon_Report.txt
 
   if [ $? -ne 0 ] ; then
 
         Error_Handling 7
         exit 7
   fi
  
########### Check the file size and throw exception accordingly ##########
 
 }
 
########House-Keeping#########
 
   function HouseKeeping
 
 {
 
    echo "Removing the Tmp Files ....."
 
   `rm -f query.tmp1 query.tmp query.out`
   `bzip2 $FILE_NAME open_order_recon_lvts.csv open_order_recon_pts.csv`
   `mv $FILE_NAME.bz2 ${SCRIPT_PATH}/archive/$FILENAME.bz2.$(date "+%Y%m%d.%H%M%S")`
   `mv open_order_recon_lvts.csv.bz2 ${SCRIPT_PATH}/archive/open_order_recon_lvts.csv.bz2.$(date "+%Y%m
%d.%H%M%S")`
   `mv open_order_recon_pts.csv.bz2 ${SCRIPT_PATH}/archive/open_order_recon_pts.csv.bz2.$(date "+%Y%m%d.
%H%M%S")`
   `cp Amount_Recon_Report.txt ${SCRIPT_PATH}/archive/Aount_Recon_Report.txt.$(date "+%Y%m%d.%H%M
%S")`
 
    cd ${SCRIPT_PATH}/archive
    varE=`ls -ltr | wc -l`
 
    if [ $varE -gt 90 ]; then
          varE=$((varE-90))
        ls -ltr | awk {'print $9'} | head -$varE >ArchiveFileList.txt
 
        for i in `cat ArchiveFileList.txt`
 
     do
 
           rm -f $i
 
     done
 
           rm -f ArchiveFileList.txt
 
    fi
 }
 
#######Notify CS-ASD#########ME
 
   function Notify_CS_ASD
 
 {
       echo "Report Generation Complete\n"
       echo "Sending mail to CS_ASD.........\n"
 
    `unix2dos -437 Amount_Recon_Report.txt Amount_Recon_Report.txt`
    `uuencode Amount_Recon_Report.txt Aount_Recon_Report.txt | mailx -r 'Amount Reconciliation' -s 'PTS-LVTS
Amount Mismatch Report' saptadip.x.sarkar@j
 
   if [ $? -ne 0 ] ; then
        echo "Attention: Unable to Send Mail\n"
        echo "A Copy Of The Report has been saved at /home/pts/temp/test/script\n"
        exit 8
   fi
 
 }
 
#########Error Handling#########
 
   function Error_Handling
 
 {
 
      echo "Error Occured whle Executing...\n"
      echo "Passing Control To Error Handler.....\n"
 
    case "$1" in
 
      1)
      echo "Error_Cd[1]: Incorrect Format of the file $FILE_NAME\n"
echo "Reason: Check the file $ FILE_NAME and ensure that the 2nd, 7th and 9th column must be order_id, direction
and open_quantity respectively\n"
      break
      ;;
 
      2)
      echo "Error_Cd[2]: Error occured while connecting to $UDB_DB\n"
      echo "Reason: Plz Chech Database connectivity along with the userid/password...\n"
      break
      ;;
 
      3)
      echo "Error_Cd[3]: Unable to create Tmp DB in TRDU\n"
      echo "Reason: Plz Chk TRDU Connectivity along with the Tmp DB size and userid/password..\n"
      break
      ;;
 
      4)
      echo "Error_Cd[4]: Error occured while doing BCP of LVTS orders in Tmp_DB\n"
      echo "Reason: Plz check the format of the open_order_recon_lvts.csv file...\n"
      break
      ;;
 
      5)
      echo "Error_Cd[5]: Error occured while doing BCP the PTS orders in Tmp_DB\n"
      echo "Reason: Plz check the format of the open_order_recon_pts.csv....\n"
      break
      ;;
 
      6)
      echo "Error_Cd[6]: Failed to Update the tmp_DB in TRDU\n"
      echo "Reason: Plz check if the userid have update permission. Also check the syntax of the update statement...\n"
      break
      ;;
 
      7)
      echo "Error_Cd[7]: Failed to Generate Amount Mismatch Report from DBPTSU\n"
      echo "Reason: Plz Check Database Connectivity, Permission of the User. Also check if the user have permission to
create files under $ SCRIPT_PATH...\n"
      break
      ;;
 
      9)
      echo "Error[9]: Row Mismatch Found Between $FILE_NAME and open_order_recon_lvts.csv\n"
      echo "Reason: Error occured during Formatting the $FILE_NAME to prepare open_order_recon_lvts.csv....\n"
      break
      ;;
 
      10)
      echo "Error_Cd[10]: File Not Found\n"
      echo "Reason: The File $FILE_NAME is Missing....\n"
      break
      ;;
 
      11)
     echo "Error_Cd[11]: Row Mismatch Found Between Data Fetched from PTS and open_order_recon_pts.csv\n"
     echo "Reason: Error occured during Formatting the Data fetched from PTS to prepare open_order_recon_pts.csv\n"
      break
      ;;
 
     *)
      exit 15;;
 
    esac
 
 }
 
 
 
 
  if [ $# -ne 1 ]; then
 
  echo " Usage: $0 <filename>"
  exit 20
 
  fi
 
 if [ -f $FILE_NAME ]; then
 
        Get_PTS_Amount
        Format_LVTS_Amount
        Format_PTS_Amount
        BCP_in_TRD
        UpdateDB
        Chk_Amount_Mismatch
        Notify_CS_ASD
        HouseKeeping
 
   else
 
        Error_Handling 10
        exit 10
  fi

Das könnte Ihnen auch gefallen