#!
/bin/bash
# Define parameters
dbname="$1"
schema_name=$2
srvname="$3"
dbuser="$4"
dbpass="$5"
basepath=$6
export PGPASSWORD="$dbpass"
# Metadata - Rowcount extraction
echo -e "\033[1;42mCREATING METADATA SQL FILE FROM GENERATOR FILE & INITIATING
METADATA EXTRACTION\033[0m"
sleep 1
psql -h $srvname -d $dbname -U $dbuser -v schema_name="$schema_name" -v
base_path="$basepath" -f $basepath/Postgres/Input/metadata_sql_gen.sql -t -q -X -o
$basepath/Postgres/Input/metadata_sql.sql
sleep 1
echo "Checking whether the input files are created or not!"
sleep 1
# File path to check
metadata_PATH="$basepath/Postgres/Input/metadata_sql.sql"
# Check if the file exists and is not empty
if [ -f "$metadata_PATH" ] && [ -s "$metadata_PATH" ]; then
echo "Files are created in input folder. Executing metadata extract SQL
Statements..."
sleep 2
psql -h $srvname -d $dbname -U $dbuser -f
$basepath/Postgres/Input/metadata_sql.sql
else
echo "Error: $metadata_PATH is not created, check the script!"
fi
# Generate SQL statements to calculate checksums
echo -e "\033[1;42mCREATING CHECKSUM SQL FILE FROM GENERATOR FILE & INITIATING
CHECKSUM EXTRACTION\033[0m"
sleep 1
psql -h $srvname -d $dbname -U $dbuser -v schema_name="$schema_name" -v
base_path="$basepath" -f $basepath/Postgres/Input/cksum_sql_gen.sql -t -q -X -o
$basepath/Postgres/Input/cksum_sql.sql
sleep 1
echo "Checking whether the input files are created or not!"
sleep 1
# File path to check
cksum_PATH="$basepath/Postgres/Input/cksum_sql.sql"
# Check if the file exists and is not empty
if [ -f "$cksum_PATH" ] && [ -s "$cksum_PATH" ]; then
echo "Files are created in input folder. Executing checksum SQL Statements..."
sleep 2
psql -h $srvname -d $dbname -U $dbuser -f $basepath/Postgres/Input/cksum_sql.sql
else
echo "Error: $cksum_PATH is not created, check the script!"
fi
# Full Extract file gen and execution
echo -e "\033[1;42mCREATING FULL EXT SQL FILE FROM GENERATOR FILE & INITIATING FULL
EXT\033[0m"
sleep 1
psql -h $srvname -d $dbname -U $dbuser -v schema_name="$schema_name" -v
base_path="$basepath" -f $basepath/Postgres/Input/fullext_sql_gen.sql -t -q -X -o
$basepath/Postgres/Input/fullext_sql.sql
sleep 1
echo "Checking whether the input files are created or not!"
sleep 1
# File path to check
fullext_PATH="$basepath/Postgres/Input/fullext_sql.sql"
# Check if the file exists and is not empty
if [ -f "$fullext_PATH" ] && [ -s "$fullext_PATH" ]; then
echo "File are created in the input folder. Executing Full extract SQL
Statements..."
sleep 2
psql -h $srvname -d $dbname -U $dbuser -f
$basepath/Postgres/Input/fullext_sql.sql
else
echo "Error: $fullext_PATH is not created, check the script!"
fi
unset PGPASSWORD
# Print text with different colors and styles
echo "Script execution complete. Press any key to exit."
# Wait for user to press any key
read -n 1 -s
echo "Exiting..."