#!/bin/sh

DATEDEBUT=`date "--date=-1 day" +%Y-%m-%d`
DATEFIN=`date +%Y-%m-%d`
CLIENT="milleroptions"
COLLECTE="flinteractive"

cd /var/scripts/flnetwork_coregistration/legacy/"$CLIENT"

#ciblage
export PGPASSWORD="SQL1281"

psql -d fl-network -h 94.23.208.41 -U postgres -f ciblage.sql

#Export fichier
FICHIER="coregistration_miller_options_"$DATEFIN".csv"
php script_milleroptions.php >> script_milleroptions.log
#Comptage lignes
TMP=`wc -l "/var/scripts/flnetwork_coregistration/legacy/$CLIENT/$FICHIER"  | cut -d' ' -f1`
if [ $TMP -gt 1 ]
then
echo "Export quotidien Miller Options/$COLLECTE du $DATEDEBUT au $DATEFIN exclu
" > corps_mail
echo $(($TMP - 1)) lignes >> corps_mail

#mutt -s "Export Miller Options/$COLLECTE $DATEDEBUT au $DATEFIN" -a "/var/scripts/flnetwork_coregistration/legacy/$CLIENT/$FICHIER" -- simon.garny@flinteractive.fr < corps_mail

mutt -s "Export Miller Options/$COLLECTE $DATEDEBUT au $DATEFIN" -a "/var/scripts/flnetwork_coregistration/legacy/$CLIENT/$FICHIER" -- laurent.lesieur.marketing@gmail.com [ cecile.dibattista@flinteractive.fr simon.garny@flinteractive.fr ] < corps_mail
fi
mv $FICHIER archives/
