1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| ##!/bin/sh
echo -n "Entrez le nom d'utilisateur PostgreSQL "
read UserPG
echo -n "Mot de passe : "
read PG_PASSWORD
csv_DirectoryLocation=$(pwd)
echo -n "Le fichier CSV se trouve-t-il dans le répertoire suivant? \n $csv_DirectoryLocation : [Oui] ou [Non]"
read answer
case $answer in
Oui|OUI|oui|O|o ) csv_location=$csv_DirectoryLocation/asso_tiers_groupe.csv
echo "Le fichier se trouve dans: $csv_location";;
Non|NON|non|N|n ) echo -n "Dans quel répertoire se trouve le fichier asso_tiers_regie.csv?"
read csv_EntryLocation
csv_location=$csv_EntryLocation/asso_tiers_groupe.csv
echo "Le fichier se trouve donc bien dans: $csv_location";;
*) "Au revoir...";;
esac
for ligne in `cat $csv_location`
do
echo $ligne
code_tiers_csv=`echo $ligne | awk -F";" '{ print $1 }'`
echo "code_tiers_csv = $code_tiers_csv"
libelle_groupe_csv=`echo $ligne | awk -F";" '{ print $2 }'`
echo "libelle_groupe_csv = $libelle_groupe_csv"
psql lorrainng_db -U $UserPG << EOF
INSERT into lorrainng_role.rasso_grp_tiers (id_groupe, numbenef, idg_regie)
SELECT group_tiers.id, tiers.numbenef, tiers.idg_regie
FROM lorrainng_role.rhabitue AS tiers, lorrainng_role.rgroupe_tiers AS group_tiers
WHERE tiers.numbenef IN (SELECT numbenef FROM lorrainng_role.rhabitue WHERE code_tiers = '$code_tiers_csv')
AND tiers.idg_regie IN (SELECT idg_regie FROM lorrainng_role.rhabitue WHERE code_tiers = '$code_tiers_csv')
AND group_tiers.id IN (SELECT id FROM lorrainng_role.rgroupe_tiers WHERE libelle = '$libelle_groupe_csv' AND idg_regie IN (SELECT idg_regie FROM lorrainng_role.rhabitue WHERE code_tiers = '$code_tiers_csv'));
EOF
done
PG_PASSWORD="" |
Partager