Professional Documents
Culture Documents
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
#
###################################################################
#
#
#
##------------------------------------------------------------------------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
###########
#### 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}
###########################################################################