#!/bin/bash
######################################################################################
# ENV DETAILS #
######################################################################################
. /home/bioddev/.bash_profile
g_ENV="DEV"
if [ "${g_ENV}" = "DEV" ]; then
export g_HOME=/home/biogen
export g_FILEHOME=/home/biogen/dev
export g_ORACLE_SID=LHNVSDEV
elif [ "${g_ENV}" = "QA" ]; then
export g_HOME=/home/bioddev
export g_FILEHOME=/home/bioddev/qa
export g_ORACLE_SID=BIODQA
fi
g_CONTACT="ryarakaraju@liquidhub.com"
#g_CONTACT="kgattupalli@liquidhub.com skarumuru@liquidhub.com syanala@liquidhub.com jfkhan@liquidhub.com"
######################################################################################
# ORACLE USER DETAILS #
######################################################################################
export g_FW_ORAUSER=LH_LOGGING
export g_FW_ORAPSWD=newuser
######################################################################################
# DIRECTORY DETAILS #
######################################################################################
g_LOGDIR=/home/bioddev/log
g_PROCDIR=/home/bioddev/process_files
g_RAWTXTFIlES=/home/bioddev/dev/inbound/legacy/load
######################################################################################
# FILE DETAILS #
######################################################################################
g_SuccessListFile=success_etl_file_list.lst
g_FailListFile=fail_etl_file_list.lst
######################################################################################
# FUNCTIONS #
######################################################################################
function gF_FileDetails ()
{
echo 'Inside gF_FileDetails'
g_File_Details=`ls -l /home/bioddev/dev/inbound/legacy/load/*.txt`
echo 'Output file details query is:' ${g_File_Details}
}
function g_File_columns ()
{
l_fileName=$1
g_col_count=`cat ${l_file_load_dir}/${l_col_file} | grep ${l_fileName} | cut -f1 -d "|"`
}
function ArchiveFile ()
{
from_dir=$1
to_dir=$2
from_filename=$3
file_typ=$4
file_ver=1
file_found='N'
encrypt_pass="LH^Open#2013F"
to_filename=${from_filename}.gpg
if [ "${file_typ}" = "S" ]; then
to_type_filename=${from_filename}.gpg
elif [ "${file_typ}" = "F" ]; then
to_type_filename=${from_filename}.gpg.fail
elif [ "${file_typ}" = "R" ]; then
to_type_filename=${from_filename}.gpg.reject
fi
gpg --yes --symmetric --passphrase=${encrypt_pass} $from_dir/$from_filename
if test `ls ${to_dir}/${to_type_filename} | grep -c ${to_type_filename}` = 0; then
mv -f $from_dir/$to_filename ${to_dir}/${to_type_filename}
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit 99
else
rm -f ${from_dir}/${from_filename}
fi
else
while [[ "${file_found}" = "N" ]]
do
to_filename_ver=${to_type_filename}.v${file_ver}
if test `ls ${to_dir}/${to_filename_ver} | grep -c ${to_filename_ver}` = 0; then
mv -f $from_dir/$to_filename ${to_dir}/${to_filename_ver}
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit 99
fi
rm -f ${from_dir}/${from_filename}
file_found='Y'
else
((file_ver+=1))
file_found='N'
fi
done
fi
}
function g_FileProcessedCheck ()
{
p_FileName=$1
g_ProcStat=`sqlplus -s ${g_FW_ORAUSER}/${g_FW_ORAPSWD}@${g_ORACLE_SID} << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 150
SELECT DECODE(land_stat_flg, 'S', 'Y', 'N')
FROM lh_procs_files a
WHERE UPPER(a.file_name) = UPPER('${p_FileName}')
AND a.insert_timestamp = (SELECT MAX(b.insert_timestamp)
FROM lh_procs_files b
WHERE UPPER(a.file_name) = UPPER(b.file_name))
/
exit
!END_SQL`
}
function g_InsertFileQCStatus ()
{
filename=`basename $1`
errortyp=$2
headreccount=$4
filereccount=$3
recnum=$5
errormsg=$6
processname=$7
srcproviderid=$8
sqlplus -s ${g_FW_ORAUSER}/${g_FW_ORAPSWD}@${g_ORACLE_SID} << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 150
exec LH_LOGGING.LH_ALL_UTILS.INSERT_FILESQCCHECK('${filename}', '${errortyp}', '${headreccount}', ${filereccount}, ${recnum}, '${errormsg}', '${processname}', ${srcproviderid})
exit
!END_SQL
}
function gF_Date_Compare_DB()
{
compareStr=$1
fileName=$2
if [[ $fileName == *PPV* ]] ; then
g_ValStat=`sqlplus -s ${g_FW_ORAUSER}/${g_FW_ORAPSWD}@${g_ORACLE_SID} << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 150
SELECT DISTINCT (DISPNSD_MONTH) FROM ODS_PPV_DISPENSE
WHERE DISPNSD_MONTH = <captured value>;
/
exit
!END_SQL`
elif [ [ $fileName == *CMOP* ] ]; then
g_ValStat=`sqlplus -s ${g_FW_ORAUSER}/${g_FW_ORAPSWD}@${g_ORACLE_SID} << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 150
SELECT DISTINCT (DISPNSD_MONTH) FROM ODS_CMOP_DISPENSE
WHERE DISPNSD_MONTH = <captured value>;
/
exit
!END_SQL`
fi
}
function gF_NumOfColumnCheck()
{
echo 'Inside Column count check'
file=$1
echo 'File name in column count check::' $1
p_ActualColCount=$2
InsertFlag='N'
LineNo=1
g_ColCheckFailFlg='N'
#var=$(awk -v var=2 -F"," -v field="$n" 'NR==2 {print $field}' file)
#var=$(awk -v var=2 -F"," 'NR==1 {print $var}' file)
var='date'
l_comp_str=`cat ${l_file_load_dir}/${l_col_file} | grep ${out_file} | cut -f1 -d ","`
RCnt=999999999999999999
while read line
do
CurrentLine="${line}"
RecColumnCount=`echo ${CurrentLine} | tr -cd ',' | wc -c`
RecColumnCount=`expr ${RecColumnCount} + 1`
if [ ${file} == 'BIOGEN_VA_PPV_DISPENSE_****.txt ' OR ${file} == 'BIOGEN_VA_CMOP_DISPENSE_****.txt ' ]; then
if [ ${LineNo} -eq 2 ]; then
var = awk '{print $1}' FS="," ${line}
fi
if [ ${LineNo} -ge 2 ]; then
linevar = awk '{print $1}' FS="," ${line}
fi
if [ ${var} != ${linevar} ]; then
echo 'Incorrect for Date Column value in the line' $'\n' | tee -a ${LOGFILE}
echo 'Date value in Column Sent in Record no '${linevar} '= ' ${RecColumnCount} $'\n' | tee -a ${LOGFILE}
g_ColCheckFailFlg='Y'
InsertFlag='Y'
fi
gF_Date_Compare_DB ${linevar} ${file}
if [ g_ValStat -gt 0]; then
echo 'Incorrect for Date Column from DB value in the line' $'\n' | tee -a ${LOGFILE}
echo 'Date value in Column Sen from DBt in Record no '${linevar} '= ' ${RecColumnCount} $'\n' | tee -a ${LOGFILE}
g_ColCheckFailFlg='Y'
InsertFlag='Y'
fi
fi
if [ ${RecColumnCount} != ${p_ActualColCount} ]; then
echo 'Incorrect no of Columns sent in the file' $'\n' | tee -a ${LOGFILE}
echo 'Expected Number of Columns Per Record =' ${p_ActualColCount} $'\n' | tee -a ${LOGFILE}
echo 'Number Columns Sent in Record no '${LineNo} '= ' ${RecColumnCount} $'\n' | tee -a ${LOGFILE}
g_ColCheckFailFlg='Y'
InsertFlag='Y'
fi
((LineNo+=1))
InsertFlag='N'
done <"$file"
}
function g_FileColCntChk()
{
p_Filename=$1
ColCntFlg=`sed -e '1,1d' ${p_Filename} | awk -v col_cnt=${g_BIOMSA_COL_COUNT} ' BEGIN {FS="|"; cnt=0} {if(NF != col_cnt) {cnt = cnt + 1}} END {print cnt}'`
if [[ ${ColCntFlg} -ne 0 ]]; then
g_TotColCheck="F"
else
g_TotColCheck="S"
fi
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.