You are on page 1of 7

#!

usr/bin/sh
###################################################################
# Author:
Doc Data ETL Team
#
# Project:
Doc Data Process enhancement
# Script Name:
doc_countersign_pending.sh
# Purpose:
Copies the File from Remote Server
# Software Used:
UNIX
#
#
#
# Input Parameters: File Name ,
file path
#
#
#
###################################################################
#
Modification Log
#
###################################################################
#
Date
Init.
Description
#
###################################################################
# 06/04/2012 Version 1.0
#
###################################################################

#
#
#

## Reading common function file


. /home/docdmgr/common/.docdata_functions
. /download/INFA/DefaultIT/Dharmas/Scripts/bin/.dharmas_unix_variables
##------------------------------------------------------------------------# Setup Process environment Variable default values
##------------------------------------------------------------------------DocBinDir=/home/docdmgr/bin
DocLogDir=/home/docdmgr/logs
InboundDir=/docdata/DefaultIT/InboundFiles
SrcDir=/docdata/DefaultIT/countersign/SrcFiles
ArchDir=/docdata/DefaultIT/countersign/Archive
TempDir=/docdata/DefaultIT/countersign/Temp
sleep_time=300
ch_prm=775
prnt_vendor=1
script_full_name=`basename $0`
proc_name=$(echo ${script_full_name} | awk -F/ '{print $NF}' )
script_name=$(echo ${proc_name} | cut -f1 -d ".")
rpt_date=`/home/docdmgr/bin/get_one_day_before_specified_date.ksh`
curr_date=`date +"%Y%m%d`
dt_tm=`date +"%Y/%m/%d %H:%M:%S"`
base_file_name="JPMC_Doc_Review_InProcess"
ib_file="${InboundDir}/InboundFile_${base_file_name}_AuditInformation.csv"
reqd_col_seq="Loan_Number,Customer_Name,Doc_Order_Date,Doc_TranGuid,Doc_Review_P
ost_Date,UserId,Package_Type,LoanGUID,LOB"
infa_folder=map_DefaultIT
infa_wfname=wf_Countersign_Correction_Pending
src_file_lst=$SrcDir/docreq_review_pending.lst
reject_file="/docdata/DefaultIT/countersign/BadFiles/JPMC_Doc_Review_InProcess.r
ej"
date_val=$1
export Mail_List="doc_data_prod_support@restricted.chase.com"
export Success_Mail_List="doc_data_prod_support@restricted.chase.com"
export MailGroup="${Mail_List},Malcolm.C.Levy@jpmorgan.com,Jeffrey.Boren@jpmorga
n.com,gmguardianllescalationrequests@wamu.net,Thomas.Simpson@jpmorgan.com,tung.d
o@chase.com,stacy.l.lam@jpmorgan.com,phillip.d.birdine@chase.com,james.t.mccurry
@chase.com,clyde.a.jones@chase.com,gm.default.recon@chase.com,laurie.castille@jp
mchase.com,Robert.st.Peters@jpmorgan.com,daniel.maldonado@chase.com,Michael.Y.Th
omas@jpmorgan.com,Antonio.arias@chase.com"

##------------------------------------------------------------------------export sql_log="${DocLogDir}/${script_name}_${base_file_name}_sql.log"
export LOG_FILE=$DocLogDir/${script_name}"_"$(date +%Y%m%d%H%M%S)".log"
touch $LOG_FILE
chmod $ch_prm $LOG_FILE
controlm_log=/home/docdmgr/logs/CONTROLM_DISPLA_FILE_TEMP.log
################################################################################
###############################
########
Deleting old controlm_log file
###################
########
This temporary log is created to display on controlm termina
l
#################
################################################################################
################################
if [ -f $controlm_log ]
then
mv $controlm_log /download/INFA/DefaultIT/Dharmas/Archive/CONTROLM_DISPLA_FILE_T
EMP_"$(date +%Y%m%d%H%M%S)".log
else
echo "Previous control log file is not found" >> $LOG_FILE
fi
touch $controlm_log
chmod 777 $controlm_log
echo "##########################################################################
##################" >> ${LOG_FILE}
echo "########################
$script_full_name
#######################
#########" >> ${LOG_FILE}
echo "##########################################################################
##################" >> ${LOG_FILE}
echo "
">> ${LOG_FILE}
echo "$script_name - Started for ${file_name} - @ $(date +%Y%m%d%H%M%S)." >> ${L
OG_FILE}
echo "
">> ${LOG_FILE}
if [ ! -z "${date_val}" ]
then
file_date=${date_val}
echo "\nDate value (i.e.${date_val}) passed as input parameter.
script will run for the file with this date. - @ $(date +%Y%m%d%H%M%S)" >> ${LOG
_FILE}
else
file_date=${rpt_date}
echo "\nNo date value passed as input parameter. script will run
for the file with following date value (i.e.default date : ${rpt_date} ) - @ $
(date +%Y%m%d%H%M%S)" >> ${LOG_FILE}
fi
file_name="${base_file_name}_${file_date}.csv"
echo "\nfile name : ${file_name} . - @ $(date +%Y%m%d%H%M%S)" >> ${LOG_FILE}
## getting file name
sh ${DocBinDir}/doc_sftp_get_inbound_file.sh -f ${base_file_name} -t ${SrcDir} d ${file_date} >> ${LOG_FILE} 2>&1
rc=$?
if [[ $rc -eq 0 && -f ${SrcDir}/${file_name} ]]
then

echo "\n${file_name} is success fully downloaded to ${SrcDir} .


- @ $(date +%Y%m%d%H%M%S)" >> ${LOG_FILE}
file_info=$(tail -1 ${ib_file} | grep "${file_name}")
echo "\nFile Info is : ${file_info} " >> ${LOG_FILE}
else
echo "\nRequested file(i.e.${SrcDir}/${file_name}) is not exists
or issues while downloading the script..Exiting the Script">> ${LOG_FILE}
mailx -s "$script_name - Failure Notification - $(date +%Y/%m/%d
) " ${Mail_List} << EOF
Recipients,
This is a Failure notification from $script_name for ${file_name} on $(
date +"%Y/%m/%d %H:%M:%S")
$script_name Started @ ${dt_tm}
But the process is failed while downloading the file.
Please look into the inbound file download process (i.e. ${DocBinDir}/do
c_sftp_get_inbound_file.sh) logs.
log files are available in $DocLogDir
This is an auto generated email ...
Please do not reply to this email.
Thanks,
DOC DATA
EOF
cat ${LOG_FILE} >> $controlm_log
exit 1;
fi
################################################################################
###########
#### START : PWD Fetch from get_connect()
####
################################################################################
###########
echo "Fetching the PWD from get function for $DB_USER_BUS" >> ${LOG_FILE}
get_connect $DB_USER_BUS $DB_SERVER_BUS >> ${LOG_FILE} 2>&1
connect_str=$DB_USER_BUS/$INFA_PWORD@$DB_SERVER_BUS
if [ "${INFA_PWORD}" ]; then
echo " PWD fetched successfully for $DB_USER_BUS " >> ${LOG_FIL
E}
else
echo "Error in get_connect(): unable to retrieve INFA_PWORD for
$DB_USER_BUS " >> ${LOG_FILE}
#mailx -s "${proc_name} :Error in getting the connect string for
Database $DB_USER_BUS@$DB_SERVER_BUS,Cannot load the file info for ${file_name}
" $Mail_List < ${LOG_FILE}
#exit 2;
fi
#----------------------------------------------------------------------------------------################################################################################

###########
#### START : Check database $DB_SERVER_BUS connectivity
####
################################################################################
###########
sqlplus -s <<EOF >> ${sql_log} 2>&1
${connect_str}
exit;
EOF
rc=$?
error_str=""
#error_str=$(grep "ORA-" ${sql_log})
echo "\nThe exit status of sqlplus is:" $rc >> ${LOG_FILE}
echo "The exit error string from the sql log file is:" ${error_str} >> ${LOG_FIL
E}
if [ ! -z "${error_str}" ]
then
echo "Error while connecting to database" >> ${LOG_FILE}
echo "The exit status of sqlplus is: $rc \n\n" >> ${LOG_FILE}
cat ${sql_log} >> ${LOG_FILE}
rm ${sql_log}
mailx -s "${proc_name} :Error in connecting Database $DB_USER_BU
S@$DB_SERVER_BUS,Cannot load the file info for ${file_name} " $Mail_List < ${LOG
_FILE}
cat ${LOG_FILE} >> $controlm_log
exit 3;
else
echo "Database connectivity for $DB_USER_BUS@$DB_SERVER_BUS is g
ood \n" >> ${LOG_FILE}
cd ${SrcDir}
rm -f $src_file_lst
touch $src_file_lst
chmod $ch_prm $src_file_lst
total_rec_cnt=0
#Creating file list
for src_file in `ls -1 $SrcDir/${base_file_name}*.csv`; do
act_col_seq=$(head -n 1 $src_file)
src_file_nm=$(echo ${src_file} | awk -F/ '{print $NF}' )
bad_src_file_nm="${src_file_nm}.bad"
req_header=$(echo ${reqd_col_seq}|tr -d " "|tr -d "\n" |
tr -d "\r"|awk '{print toupper($0)}')
act_header=$(echo ${act_col_seq}|tr -d " "|tr -d "\n" |
tr -d "\r"|awk '{print toupper($0)}')
echo "\nSource File Name :\t ${src_file_nm}" >> ${LOG_FI
LE}
echo "\nRequired header value :\t${req_header}" >> ${LOG
_FILE}
echo "Actual header value in the file :${act_header}" >>
${LOG_FILE}
if [ "${req_header}" == "${act_header}" ]
then
echo "\nActual header value is matching
with required header value">> ${LOG_FILE}
rec_cnt=$(wc -l ${SrcDir}/${src_file_nm}
| awk '{print $1}')

file_rec_cnt=$(expr $rec_cnt - 1)
total_rec_cnt=$(expr $total_rec_cnt + $f
ile_rec_cnt )
echo $src_file_nm >> $src_file_lst
sh ${DocBinDir}/doc_inbound_load_file_in
fo.sh -f ${src_file_nm} -t ${SrcDir} -v ${prnt_vendor} >> ${LOG_FILE} 2>&1
rc=$?
echo "\nFile information load into PRNT_
VEND_FILE_ACK table is completed with status: $rc - @ $(date +%Y%m%d%H%M%S)">> $
{LOG_FILE}
else
echo "\nActual header value in the file
is not matching with required header value - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FI
LE}
mv -f ${SrcDir}/${src_file_nm} ${ArchDir
}/${bad_src_file_nm}
echo "\nPlease find the file (i.e. ${bad
_src_file_nm} ) in ${ArchDir} directory">> ${LOG_FILE}
echo "Please check with file provider re
garding the issue .. \n\nThanks,\nDoc Data">> ${LOG_FILE}
mailx -s "${proc_name} :${src_file_nm} F
ile header value is not matching as per the requirement " $Mail_List < ${LOG_FIL
E}
fi
done
fi
#get the file count
file_cnt=$(wc -l $src_file_lst | awk '{print $1}')
if [[ $file_cnt -ge 1 && $total_rec_cnt -ge 1 ]]
then
echo "\nWe have ${file_cnt} files with ${total_rec_cnt} records
to load into database ">> ${LOG_FILE}
## Starting Informatica work flow
echo "\nRunning Infa workflow $infa_wfname in folder $infa_folde
r - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE}
$DocBinDir/run_infa_job.ksh $infa_wfname $infa_folder >> ${LOG_F
ILE} 2>&1
rc=$?
if [ $rc -eq 0 ]
then
echo "\nInformatica Workflow (i.e. $infa_wfname
) is successfully completed - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE}
##getting reject record count
rec_cnt=$(wc -l ${reject_file} | awk '{print $1}
')
rej_rec_cnt=$(expr $rec_cnt - 1)
if [[ -f ${reject_file} && ${rej_rec_cnt} -ge 1
]]
then
reject_file_name=$(basename ${re
ject_file})
arch_reject_file_name="${reject_
file_name}.${file_date}.csv"
echo "\nreject file (i.e.${rejec
t_file_name} ) with ${rej_rec_cnt} records is created while loading - @ $(date
+%Y%m%d%H%M%S)">> ${LOG_FILE}

uuencode ${reject_file} ${reject


_file_name} | mailx -s "Reject File for ${base_file_name} File for date: ${curr_
date}" ${Mail_List}
#moving reject file to archive d
irectory
echo "\nAfter sending the email,
the reject file(i.e.${reject_file_name} ) moved to archive directory (i.e.${Ar
chDir} - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE}
chmod $ch_prm ${reject_file} ;mv
${reject_file} ${ArchDir}/${reject_file_name}
else
echo "\nreject file (i.e.${rejec
t_file} ) is not created or it has 0 records in the file - @ $(date +%Y%m%d%H%M%
S)">> ${LOG_FILE}
fi
else
echo "\nWork flow (i.e. $infa_wfname ) in $infa_
folder is failed - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE}
mailx -s "${proc_name} - Work flow (i.e. $infa_w
fname ) is failed - $(date +%Y%m%d) " $Mail_List < ${LOG_FILE}
cat ${LOG_FILE} >> $controlm_log
exit 5;
fi
else
echo "\nThere are no files to load or files may have 0 records. ">> ${LO
G_FILE}
fi
# sending and archiving the files.
if [ $file_cnt -ge 1 ] ; then
while read file_nm ;do
file_date=$(echo $file_nm | awk -F. '{print $1}' |awk -F_ '{prin
t $NF}' )
echo "\nSending ${file_nm} to mail group - @ $(date +%Y%m%d%H%M%
S)">> ${LOG_FILE}
uuencode ${SrcDir}/${file_nm} ${file_nm} | mailx -s "${base_file
_name} for date: ${file_date}" ${MailGroup}
mv ${SrcDir}/${file_nm} ${ArchDir}/${file_nm} ;gzip -f ${ArchDir
}/${file_nm}
echo "\nFile is compressed (i.e. ${file_nm}.gz ) and archived i
n ${ArchDir} - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE}
done < $src_file_lst
else
echo "\nNo files to send - @ $(date +%Y%m%d%H%M%S)">> ${LOG_FILE
}
fi
echo "\nProcess Completed successfully and exiting the script - @ $(date +%Y%m%d
%H%M%S)">> ${LOG_FILE}
echo "\n------------------------------------------------------------- @ $(date +
%Y%m%d%H%M%S)">> ${LOG_FILE}
mailx -s "${proc_name} :$infa_wfname Completed successfully - @ $(date +%Y/%m/%
d)" $Mail_List < ${LOG_FILE}
cat ${LOG_FILE} >> $controlm_log
exit 0;
###########################################################################
###
End of the Script

###########################################################################

You might also like