71 lines
3.2 KiB
Bash
Executable File
71 lines
3.2 KiB
Bash
Executable File
#!/bin/bash -e
|
|
|
|
|
|
#/****************************************************************
|
|
#****** ForeWarn Licensing and / or usage Terms and Conditions *****
|
|
#ForeWarn. The NextGen Insights Solution Platform
|
|
|
|
#Copyright © 2021 COMPEGENCE. All Rights Reserved
|
|
|
|
#ForeWarn is a product of COMPEGENCE.
|
|
|
|
#To be used only with a valid license from COMPEGENCE
|
|
|
|
#www.compegence.com info@compegence.com
|
|
#****************************************************************/
|
|
|
|
|
|
#HOME="/home/compegence/customer"
|
|
#Directories
|
|
fileDir="/data/customer/MMT"
|
|
homeDir=$HOME/customer/MMT
|
|
configDir=$homeDir/conf
|
|
input_file=$configDir/etl-config.txt
|
|
declare -A credentials
|
|
while IFS="=" read -r key value; do
|
|
credentials[$key]=$value
|
|
done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file )
|
|
#for i in ${credentials[@]}; do echo ***$i; done
|
|
|
|
user=${credentials[user]}
|
|
password=${credentials[password]}
|
|
host=${credentials[host]}
|
|
db=${credentials[db]}
|
|
protocol=${credentials[protocol]}
|
|
server=${credentials[server]}
|
|
|
|
postgres_con="psql -A -t postgresql://$user:$password@$host/$db"
|
|
|
|
$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='Initial', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'"
|
|
|
|
|
|
count=`$postgres_con -c "select count(*) from fw_core.fw_jobctl_file_runschedule"`
|
|
if [[ $count -eq 0 ]]
|
|
then
|
|
$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='file_found_to_process', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'"
|
|
else
|
|
while IFS= read -a filenames
|
|
do
|
|
file_name=$(echo $filenames | sed 's/[[:space:]]/\\ /g')
|
|
if [[ -f $fileDir/files/landing/$filenames ]];
|
|
then
|
|
echo "File: $file_name is already processed and is moved to Duplicate Folder"
|
|
move=$(echo "mv $fileDir/files/landing/$file_name $fileDir/files/duplicate_file/$file_name")
|
|
eval $move
|
|
|
|
#update ctl table to exit for duplicate files
|
|
$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='duplicate_file_found', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'"
|
|
else
|
|
|
|
filecount=find $fileDir/files/landing/ -type f -name "*.xlsx" 2> /dev/null |wc -l 1> /dev/null
|
|
if [[ $filecount -eq 0 ]]
|
|
then
|
|
$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'No files in Landing folder', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'"
|
|
else
|
|
$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'file_found_to_process', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'"
|
|
fi
|
|
fi
|
|
done < <($postgres_con -c "select file_name from fw_core.fw_jobctl_file_runschedule where end_status_note='ODS_completed' and end_status ='success'")
|
|
fi
|
|
|