#!/bin/sh
#####################################################################################################
#    Program name : Data import
#
#    File name : XXT_DATALOAD
#
#    describe : Get the core data file , Import into database
#    Notes:
#       1) Copy all host (shell) programs to the correct XXT_TOP/bin
#       2) chmod +x  programs
#          eg:chmod +x XXT_DATALOAD
#
#  Change History
#  Date          Author             Version Change Reference
#  -----------   ------------------ ------- ----------------------------------
#  20130901      huangrx            1.0     Create
######################################################################################################
PROG_NAME=${0}
LOGON=${1}
USER_ID=${2}
APP_USER_NAME=${3}
REQUEST_ID=${4}

#Date paremeter
FILE_DATE=${5}

echo "+---------------------------------------------------------------------------+"
echo "Program parameters are : "
echo " "
echo "  Program name           : " $PROG_NAME
echo "  User ID                : " $USER_ID
echo "  Application user name  : " $APP_USER_NAME
echo "  Request ID             : " $REQUEST_ID
echo "  Accounting date        : " $FILE_DATE
echo "+---------------------------------------------------------------------------+"

if [ "$FILE_DATE" = "" ] ; then
   echo "Error: the Parameter of control date is null!"
   exit 1;
fi

##FTPUSER Get the path of the core data file from the configuration file (ftpdir=<HOME route >/interface_data)
CONFIG_PATH=$XXT_TOP/bin/config.ini
SHOME=`awk -F "=" '{if($1=="ftpdir") print $2}' $CONFIG_PATH`
## Data file source path
SOURCE_PATH=$SHOME
## Data file destination path
DESTINATION_PATH=$XXT_TOP/bin/interface_data
##SQLLDR The directory of the control file used
CTRL_PATH=$XXT_TOP/bin/ctrl
## File name prefix ( Without extension and date )
FILE_SUFFIX=rate
## File name extension format
FILE_EXT=".dat"
## Total number of cycles
COUNT=120

## Data file name
FILE_NAME=${FILE_SUFFIX}${FILE_DATE}${FILE_EXT}
## After file segmentation DATA file
DATA_FILE=${FILE_SUFFIX}_data${FILE_DATE}.dat_split
## After file segmentation END file
END_FILE=${FILE_SUFFIX}_end${FILE_DATE}.dat_split
##DATA Of documents CTRL file
DATA_CTRL=XXT_$(echo ${FILE_SUFFIX} | tr '[a-z]' '[A-Z]')_LOAD_DATA.ctrl
##END Of documents CTRL file
END_CTRL=XXT_$(echo ${FILE_SUFFIX} | tr '[a-z]' '[A-Z]')_LOAD_END.ctrl
##SQLLDR DATA File error file
DATA_BAD=${FILE_SUFFIX}_data_${FILE_DATE}.bad
##SQLLDR DATA The log file of the file
DATA_LOG=${FILE_SUFFIX}_data_${FILE_DATE}.log
##SQLLDR END File error file
END_BAD=${FILE_SUFFIX}_end_${FILE_DATE}.bad
##SQLLDR END The log file of the file
END_LOG=${FILE_SUFFIX}_end_${FILE_DATE}.log

## take FILE_DATE Convert to YYYY-MM-DD
FILE_DATE=`echo $FILE_DATE |sed 's/-//g'`

## Format in the agreed format FILE_DATE
FILE_DATE=`sqlplus -s $LOGON <<EOF
set echo off
set verify off
set head off
set feedback off
select to_char(to_date($FILE_DATE, 'yyyy-mm-dd hh24:mi:ss'), 'yyyymmdd') from dual;
EOF`
FILE_DATE=`echo $FILE_DATE |sed 's/ //g'`

echo "Step1--Start to fetch ${FILE_SUFFIX} files!"

cd ${DESTINATION_PATH}

if [ -d ${DESTINATION_PATH}/${FILE_DATE} ] ; then
   cd ${FILE_DATE}
   rm -rf ${DATA_FILE}
   rm -rf ${END_FILE}
else
   mkdir ${FILE_DATE}
   cd ${FILE_DATE}
fi

while [ $COUNT -gt 0 ]
do
    
  if [ -f ${SOURCE_PATH}/${FILE_NAME} ] ; then
     cp -f ${SOURCE_PATH}/${FILE_NAME} ${DESTINATION_PATH}/${FILE_DATE}
     break
  fi
      
  COUNT=`expr $COUNT - 1`
  echo "loop--$COUNT times"
  sleep 300

done

if [ $COUNT -eq 0 ] ; then
   echo "${FILE_SUFFIX} files are not ready!"
   echo "Please reload ${FILE_SUFFIX} files and run request again manually"
   exit 1
else
   echo "finish fetch ${FILE_SUFFIX} files successfully!"
fi

echo "Step2--Start to delete bad&log files already exist"
## Delete existing error files and log files
cd ${DESTINATION_PATH}/${FILE_DATE}
rm -rf ${DATA_BAD}
rm -rf ${DATA_LOG}
rm -rf ${END_BAD}
rm -rf ${END_LOG}

echo "Step3--Start to split ${FILE_NAME}"
## Divide the data file into DATA( data ) and END( The total number of data records ) file
cd ${DESTINATION_PATH}/${FILE_DATE}
sed '$d' ${FILE_NAME} > ${DATA_FILE}
cat ${FILE_NAME} | grep "^END!" > ${END_FILE}

echo "Step4--Start SQL*Loader"
## Loading data files
echo "######Run SQL*Loader, LOAD $DATA_FILE INTO XXT_DATA_TEMP_B######"
sqlldr userid=${LOGON} control=${CTRL_PATH}/${DATA_CTRL} data=${DESTINATION_PATH}/${FILE_DATE}/${DATA_FILE} bad=${DESTINATION_PATH}/${FILE_DATE}/${DATA_BAD} log=${DESTINATION_PATH}/${FILE_DATE}/${DATA_LOG} direct=ture
## If the error file exists , It means that something went wrong , sign out
##bad File only if data exception ,Load When you don't go in , Generation . Grammatical errors , Or the file does not exist, the error is not generated bad file
##SQLLDR Command returns status
RETCODE=$?
if [ -f ${DESTINATION_PATH}/${FILE_DATE}/${DATA_BAD} ] ; then
echo "######## Error records are found, please check ${DATA_LOG} and fix them! #########"
exit 1
fi
if [ $RETCODE -ne 0 ]; then
echo "######## Program Error Or table and file not exist, please check ${DATA_LOG} and fix them! #########"   
exit 1
fi

## Load data records total number of files
echo "######Run SQL*Loader, LOAD ${END_FILE} INTO XXT_DATA_END_B######"
## If the error file exists , It means that something went wrong , sign out
sqlldr userid=${LOGON} control=${CTRL_PATH}/${END_CTRL} data=${DESTINATION_PATH}/${FILE_DATE}/${END_FILE} bad=${DESTINATION_PATH}/${FILE_DATE}/${END_BAD} log=${DESTINATION_PATH}/${FILE_DATE}/${END_LOG} direct=ture
##SQLLDR Command returns status
RETCODE=$?
if [ -f ${DESTINATION_PATH}/${FILE_DATE}/${END_BAD} ] ; then
echo "######## Error records are found, please check ${END_LOG} and fix them! #########"
exit 1
fi
if [ $RETCODE -ne 0 ]; then
echo "######## Program Error Or table and file not exist, please check ${END_LOG} and fix them! #########"   
exit 1
fi

echo "Step5--Delete 7 days before files"
## Only keep 7 Days of historical data
FILE_DATE_PRE=`sqlplus -s $LOGON <<EOF
set echo off
set verify off
set head off
set feedback off
select to_char(to_date($FILE_DATE,'yyyymmdd')-7,'yyyymmdd') from dual;
EOF`
FILE_DATE_PRE=`echo ${FILE_DATE_PRE} |sed 's/ //g'`

## obtain 7 The file name of the data file
PRE_FILE_NAME=${FILE_SUFFIX}${FILE_DATE_PRE}${FILE_EXT}

## Delete 7 Data files from the day before , Including source and target files
rm -rf ${SOURCE_PATH}/{PRE_FILE_NAME}
rm -rf ${DESTINATION_PATH}/${FILE_DATE_PRE}/${DATA_FILE}
rm -rf ${DESTINATION_PATH}/${FILE_DATE_PRE}/${END_FILE}

EBS in HOST Host concurrent request template for more related articles

  1. OAF_ Development series 25_ Realization OAF in Java Type concurrency program development oracle.apps.fnd.cp.request( Concept )

    20150719 Created By BaoXinjian

  2. 03: zabbix API Interface Yes host 、 Host group 、 Templates 、 Application set 、 Monitoring item 、 Trigger, etc

    Catalog :Django Other articles 01: install zabbix server 02:zabbix-agent Installation configuration And web Interface management 03: zabbix API Interface Yes host . Host group . Templates . Application set . Monitoring item . ...

  3. oracle EBS Use in PLSQL Submit &quot; Turn off discrete &quot; Concurrent request

    declare l_request_id number; l_return_flag boolean; l_num_user_id number; l_num_resp_id number; l_nu ...

  4. java How to simulate real concurrent requests in ?

    Sometimes you need to test the concurrency performance of a function , And don't try to use other tools , Just use your own development language , A concurrent request is the most convenient . java Simulate concurrent requests in , Nature is very convenient , Just a few more threads , Just make a request . however , Such request , ...

  5. python web Concurrent requests in

    python web You can choose django, You can also choose flask, They work the same way .flask More light , Let's write a paragraph flask Program to illustrate python web Processing of concurrent requests . app.py import ...

  6. JS How to deal with multiple ajax Concurrent request ?

    js Multiple concurrent processing in . Usually To reduce page load time , First, display and process the core content , Send it after loading the page ajax Request additional data There may be more than one ajax request , For the user experience , It's better to send parallel requests , That's where it comes in and asks ...

  7. Oracle EBS Clear concurrent requests and ( or ) Manager data request

    Request description : This request can clear the request log file submitted at ordinary times . Log file for concurrency Manager . Report output file . History information of concurrent requests and concurrent manager processes .  Parameter description :( The fields marked in red are required )1.   Entity :ALL: Clear request history . ...

  8. EBS All running concurrent requests on a single instance and the current state of the request

    --EBS All running concurrent requests on a single instance and the current state of the request --- Summary of all concurrent requests running on an instance and their current status and waiting status     select w.seconds_in_wait "Se ...

  9. EBS Use in JAVA Mode sending HTML Format mail

    from huan.gu special column :http://blog.csdn.net/gh320/article/details/17174769 EBS Use in JAVA Mode sending HTML Format mail One . development tool :JDevel ...

Random recommendation

  1. session and cookie The difference and connection

    1. Create a new Cookie Cookie cookie = new Cookie("username",name); 2. Set up cookie How long will it survive on the client cookie.set ...

  2. Win8 &amp; WP8.1 Lightweight database

    since Win8 and WP8.1 since ,MS hold SQL CE Removed . For your own convenience APP upgrade , Reduce code change momentum , So I wrote a small database management , Reference resources WP8.1 Previous DataContext. It takes less time , It took a few days ...

  3. Java Interview “ rival ” Threads ,9 A comprehensive analysis of questions

    author : I'm the Sieger ( One ) How to create threads (1) Realization Runnable Interface (2) Inherit Thread class Recommended interface , Be able to separate definition from implementation , Less coupling ( Two ) About the priority of threads thread2.setPrio ...

  4. 26.QT- Custom delegation of model view

    In the last chapter, learn  25.QT- Model view   after , This chapter goes on to learn about view delegation View delegation (Delegate) brief introduction Because models are responsible for organizing data , And the view is responsible for displaying the data , So when the user wants to modify the displayed data , It's done through delegation in the view View ...

  5. MATLAB System Generator First time to know

    MATLAB System Generator First time to know simulation model : Simulation results : Use system generator The specific steps of building low-pass filter : Open the library , For details of the components in the library, see UG958 file Add digital filters ...

  6. Second articles : Present content _ Section 1 :Control present

    One .Control The presentation process of In the last chapter ““ Life and death are in order ” Control lifecycle for ” in , We mentioned Render Is the protagonist of control development , But in the control tree “ Synthesis mode (Composite)” Some of the protagonists are absent ( The reason why there are too many scenes ). Oh ...

  7. Use the latest version of Adobe Photoshop CC 2017

    1. It is suggested that the old one should be replaced before installation Photoshop Delete Ganjing . Open the website  https://www.adobe.com/cn/products/photoshop.html   Use it for free , Will download an installer Crea ...

  8. esxi It causes vm Bind float IP Can't communicate with the outside

    stay vmware esxi Environment by creating VM installation is complete openstack after , Discovery creates Instance After that, the network doesn't work , After many investigations , It was decided that vmware esxi Standard switch rejected “ Hybrid mode ” Caused by , So open “ Hybrid ...

  9. vue router Use query and params The use of Chuanshen

    Parameter transfer is an operation that the front end often needs to use , Many scenarios will need to use the parameters of the previous page , This article will introduce in detail vue router How to transmit parameters , And some small details . Friends in need can make a reference , I hope I can help you . Vue ...

  10. solve phantomjs Output Chinese random code

    solve phantomjs Output Chinese random code , Can be in js Add the following statement to the file : phantom.outputEncoding="gb2312"; // Solve the output garbled code