#!/bin/sh # # PURPOSE: Load Facilitie data files into the database IDEAWS. # Author: Jeff Yuan # Date: 11/11/1998 # Data Source: Facilities data # Revision: #------------------------------------------------------------------------- # INPUT: parameters: data file name (in $FACILITY_RCV) or none # LOGIC: If the file name is given, this procedure takes this file # from $FACILITY_RCV directory and loads it. Else, all *.dat # files existing in $FACILITY_RCV directory are loaded. # Usage to call "C" loading program: # facility_loader # For each loading file: # - if loading is correct, this procedure writes a log file in # in $FACILITY_LOG which is named with loading name plus "_ok" & # ".log" extension. Then the loaded data file is removed to # $FACILITY_HOLD. # - else loading is not correct, this procedure writes a log file # in $FACILITY_LOG which is named with loading name plus "_err" & # ".log" extension. Then the unloaded data file is removed to # $FACILITY_HOLD. # For all loading files: # -This procedure writes a report file in $FACILITY_LOG which # contains number of loaded files, number of unloaded files # and some other global informations about loading. # ------------------------------------------------------------------------ set -xv . ~ideaws/.profile #initialize some variables #------------------------- UNIQ=$$ total_files=0 unloaded_files=0 loaded_files=0 start_date=`date` II_DATE_FORMAT=MULTINATIONAL export II_DATE_FORMAT FACILITY_LOG=/users3/ideaws/facility/log export FACILITY_LOG FACILITY_RCV=/users3/ideaws/facility/rcv export FACILITY_RCV FACILITY_HOLD=/users3/ideaws/facility/hold export FACILITY_HOLD FACILITY_EXE=/users3/ideaws/facility/loader export FACILITY_EXE report_file=$FACILITY_LOG/FACILITY_data.rpt log_ext="_ok.log" err_log_ext="_err.log" ING_SET="set lockmode session where level=table; set session with on_error =rollback transaction;" export ING_SET #go to the directory of files reception #-------------------------------------- cd $FACILITY_RCV # start loading #-------------- if [ $# -eq 1 ] then ############## #load one file data_file="$1" log_name=`echo $data_file | awk '{split($0,a,".");print a[1];}'` $FACILITY_EXE/facility_loader $data_file if [ $? -eq 99 ] then # loading Ok # remove data file to $FACILITY_HOLD loaded_files=`expr $loaded_files + 1` echo $data_file >> loaded_list mv $data_file $FACILITY_HOLD log_file=$FACILITY_LOG/$log_name$log_ext echo "file $data_file is loaded" >> $log_file cat loading.log >> $log_file rm loading.log else # loading DATA is not Correct # remove data file to $FACILITY_HOLD unloaded_files=`expr $unloaded_files + 1` echo $data_file >> unloaded_list mv $data_file $FACILITY_HOLD log_file=$FACILITY_LOG/$log_name$err_log_ext$UNIQ echo "file $data_file is not loaded" >> $log_file fi total_files=`expr $total_files + 1` else #################################################### #loop of loading on all files being in $IDEA_RCV_RDH if [ -f *.dat ] then for data_file in *.dat do log_name=`echo "$data_file" | awk '{split($0,a,".");print a[1];}'` $FACILITY_EXE/facility_loader "$data_file" if [ $? -eq 99 ] then # loading Ok # remove data file to $FACILITY_HOLD loaded_files=`expr $loaded_files + 1` echo "$data_file" >> loaded_list mv "$data_file" $FACILITY_HOLD log_file=$FACILITY_LOG/$log_name$log_ext echo "file '$data_file' is loaded" >> $log_file cat loading.log >> $log_file rm loading.log else # loading DATA is not Correct # remove data file to $FACILITY_HOLD unloaded_files=`expr $unloaded_files + 1` echo "$data_file" >> unloaded_list mv "$data_file" $FACILITY_HOLD log_file=$FACILITY_LOG/$log_name$err_log_ext$UNIQ echo "file '$data_file' is not loaded" >> $log_file fi total_files=`expr $total_files + 1` done fi fi # make a summary of data loading #------------------------------- stop_date=`date` echo "*******************************************************" >> $report_file echo " Facility DATA LOADING SUMMARY -- `date` " >> $report_file echo " < FACILITIES Data >" >> $report_file echo "Started at : $start_date " >> $report_file echo "Finished at : $stop_date " >> $report_file echo "-------------------------------------------------------" >> $report_file echo "No of Files to be loaded : " $total_files >> $report_file echo "No of Files loaded : " $loaded_files >> $report_file echo "No of Files not loaded : " $unloaded_files >> $report_file echo "------------------------------------------------------" >> $report_file if [ -f loaded_list ] then echo "List of Data files loaded :" >> $report_file cat loaded_list >> $report_file echo "-----------------------------------------------" >> $report_file rm loaded_list fi if [ -f unloaded_list ] then echo "List of Data files not loaded :" >> $report_file cat unloaded_list >> $report_file echo "----------------------------------------------" >> $report_file rm unloaded_list fi