Skip to content

Instantly share code, notes, and snippets.

@Cabeda
Last active May 5, 2021 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cabeda/2e854b5c2e7cad6dae1ca6104dba4a33 to your computer and use it in GitHub Desktop.
Save Cabeda/2e854b5c2e7cad6dae1ca6104dba4a33 to your computer and use it in GitHub Desktop.
#!/bin/bash
while getopts ":i:o:" opt; do
case $opt in
i) input="$OPTARG"
;;
o) output="$OPTARG"
;;
t) title="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
dups=$(cat $input | uniq -d)
unique_ids=$(cat $input | uniq)
num_unique_ids=$(cat $input | uniq | wc -l| awk '{print $1}')
num_dups=$(cat $input | uniq -d | wc -l | awk '{print $1}')
num_outputs=$(cat $output | wc -l | awk '{print $1}')
if [ $num_unique_ids -lt $num_outputs ]
then
echo "The number of inputs is less than outputs ($num_unique_ids < $num_outputs). Please check with integrations team..."
exit 1
fi
echo "There are $num_dups duplicates"
echo ""
echo "Removing dups for these ID's:"
echo $dups
echo ""
read -p "Gdpr title: " title
read -p "Request date (YYYY-MM-DD): " request_date
read -p "Due date (YYYY-MM-DD): " due_date
read -p "Request type (account|contact): " request_type
read -p "Account_id: " account_id
echo "insert into dwhrw.dwh_gdpr.gdpr_requests(title,request_date,due_date, request_type, account_id, gdpr_id, request_status, is_before_auto_process, request_insert_type) VALUES" > auto_bi.sql
echo "Writing $num_unique_ids ids"
for id in $unique_ids; do
echo "('$title',date('$request_date'),date('$due_date'),'$request_type','$account_id','$id', 'Ready', True, 'Manual')," >> auto_bi.sql
done
# Opens the output file
echo "Opening the output file"
open auto_bi.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment