my_imp_database.sh

# ==================================================
# Nom :
# Objet :
# Auteur :
# Cree le :
# Syntaxe : user pwd database_FROM_name database_TO_name
# ==================================================
user=$1
pwd=$2
databasefrom=$3
databaseto=$4
w_date=$(date '+%Y%m%d_%H%M%S')
logpath=/exploit/logs
logfile=my_import_${databaseto}_${w_date}.log
dumpfile=/exploit/dumps/my_exp_${databasefrom}.sql
sqlfile=/exploit/logs/my_imp_${databaseto}_${w_date}.sql
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 $1 user $2 pwd $3 database_FROM_name $4 database_TO_name"
}
# ----------------------------------
# --------------------------
# Verification de la syntaxe
# --------------------------
#if [ $# -ne 3 -a $# -ne 4 ]
if [ $# -lt 3 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
echo "-------------------------------------------------"
echo " DROP and CREATE DATABASE $databaseto;"
echo "-------------------------------------------------"
# tee $logpath/$logfile;
#echo "DROP DATABASE if exists $databaseto;">$sqlfile;
#echo "CREATE DATABASE IF NOT EXISTS $databaseto;">>$sqlfile;
#echo "show databases;">>$sqlfile;
#echo "use $databaseto;">>$sqlfile;
#echo "source $dumpfile;">>$sqlfile;
#echo ""
#cat $sqlfile;
#mysql --show-warnings -u $user -p${pwd} <$sqlfile >$logpath/$logfile;
mysql --show-warnings -u $user -p${pwd} << EOF
 warnings;
 DROP DATABASE if exists $databaseto;
 CREATE DATABASE IF NOT EXISTS $databaseto;
 show databases;
 use $databaseto;
 source $dumpfile;
EOF
echo "-------------------------------------------------"
# cat $logpath/$logfile

my_exp_database.sh

#!/bin/bash
# ==================================================
# Nom : my_exp_database.sh
# Objet : export database
# Auteur : N.LAMOTTE
# Cree le : 08/02/2012
# Syntaxe : my_exp_database.sh user pwd database_name (otheroption1, otheroption2, otheroption1otheroption3 not mandatory)
# ==================================================
user=$1
pwd=$2
database=$3
otheroption1=$4
otheroption2=$5
otheroption3=$6
w_date=$(date '+%Y_%m_%d_%H_%M_%S')
logpath=/exploit/logs
dumppath=/exploit/dumps
logfile=my_exp_${database}_${w_date}.log
dumpfile=my_exp_${database}.sql
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 $1 user $2 pwd $3 database_name ($4 otheroption1 $5 otheroption2 $6 otheroption3 not mandatory)"
}
# ----------------------------------
# --------------------------
# Verification de la syntaxe
# --------------------------
#if [ $# -ne 3 -a $# -ne 4 ]
if [ $# -lt 3 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
if [ $# -gt 4 ]
then
 echo "mysql with option $otheroption1 $otheroption2 $otheroption3"
 dumpfile=my_exp_${database}_withoption.sql
 logfile=my_exp_${database}_withoption_${w_date}.log
fi
#mysqldump -u $user -p${pwd} $database $otheroption1 $otheroption2 $otheroption3 --log-error=$logpath/$logfile > $dumppath/$dumpfile
mysqldump -u $user -p${pwd} -v $database $otheroption1 $otheroption2 $otheroption3 > $dumppath/$dumpfile

my_exp_database_host.sh

#!/bin/bash
# ==================================================
# Nom : my_exp_database.sh
# Objet : export database
# Auteur : N.LAMOTTE
# Cree le : 08/02/2012
# Syntaxe : my_exp_database.sh user pwd database_name (otheroption1, otheroption2, otheroption1otheroption3 not mandatory)
# ==================================================
user=$1
pwd=$2
database=$3
host=$4
otheroption1=$5
otheroption2=$6
otheroption3=$7
w_date=$(date '+%Y_%m_%d_%H_%M_%S')
logpath=/exploit/logs
dumppath=/exploit/dumps
logfile=my_exp_${database}_${w_date}.log
dumpfile=my_exp_${database}.sql
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 $1 user $2 pwd $3 database_name $4 host ($5 otheroption1 $6 otheroption2 $7 otheroption3 not mandatory)"
}
# ----------------------------------
# --------------------------
# Verification de la syntaxe
# --------------------------
#if [ $# -ne 3 -a $# -ne 4 ]
if [ $# -lt 4]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
if [ $# -gt 5 ]
then
 echo "mysql with option $otheroption1 $otheroption2 $otheroption3"
 dumpfile=my_exp_${database}_withoption.sql
 logfile=my_exp_${database}_withoption_${w_date}.log
fi
#mysqldump -u $user -p${pwd} $database $otheroption1 $otheroption2 $otheroption3 --log-error=$logpath/$logfile > $dumppath/$dumpfile
mysqldump -h $host -u $user -p${pwd} -v $database $otheroption1 $otheroption2 $otheroption3 > $dumppath/$dumpfile

my_ET_tst.sh

w_date=$(date '+%Y_%m_%d_%H_%M_%S')
nb_jour=$1 # Nombre de jour
cmd=$(mysql -u redsrv -pmotdepasse redmine --skip-column-names << EOF
select concat('RAILS_ENV=production rake redmine:plugins:project_extras:reminder_by_ids issues="',group_concat(t1.id SEPARATOR ' '),'" message="blabla" user="ET"')
from issues t1
where datediff(current_date , t1.updated_on) <= $1;
EOF)
echo $cmd
$cmd

my_backup_database.sh

w_date=$(date '+%Y_%m_%d_%H_%M_%S')
# avec generation log
# su mysql --command="mysqlbackup --user=root --password=motdepasse --ibbackup=/opt/mysql/meb-3.5/bin/ibbackup /etc/mysql/my.cnf /data/backups/mysql" > /exploit/logs/my-backup-${w_date}.log
# sans log pour remonter dans VTOM
su mysql --command="mysqlbackup --user=root --password=motdepasse --ibbackup=/opt/mysql/meb-3.5/bin/ibbackup /etc/mysql/my.cnf /data/backups/mysql"

my_backup_binlog.sh

w_date=$(date '+%Y_%m_%d_%H_%M_%S')
BINLOGPATH=/data/mysql/databases
BINLOGNAME=mysql-bin.index
BACKUPDIR=/data/backups/mysql/${w_date}_binlog
# sans log pour remonter dans VTOM
#su mysql --command="mysqlbackup --user=root --password=zsxedc --ibbackup=/opt/mysql/meb-3.5/bin/ibbackup /etc/mysql/my.cnf /data/backups/mysql"
echo "Flush Logs"
mysql -pzsxedc --batch --skip-column-names --execute="flush logs"
echo "Copying binlogs"
su mysql --command="mkdir $BACKUPDIR"
for FILE in `cat $BINLOGPATH/$BINLOGNAME`
do
SFILE=(${FILE/*\//})
#echo "$SFILE"
su mysql --command="cp -p $BINLOGPATH/$SFILE $BACKUPDIR/"
#gzip $/$SFILE
done

my_alter_engine_mig.sh

#!/bin/bash
file=/exploit/scripts/my_alter_table_engine_mig.sql
file2=/exploit/scripts/my_alter_table_engine_mig_spe.sql
mysql -pzsxedc --batch --skip-column-names --execute="select concat('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=InnoDB;') from information_schema.TABLES where table_schema not in ('information_schema', 'mysql', 'performance_schema') and table_type <> 'VIEW' and engine <> 'InnoDB' and table_name not in ('General Ledger','Controlling#temporary','Overdue-DrillThrough')" > $file
cat $file
time mysql -pzsxedc <$file
cat $file2
time mysql -pzsxedc <$file2

my_alertlog.sh

#!/bin/sh
echo "----------------------------------------------"
echo " Recherche des erreurs dans les log"
echo "----------------------------------------------"
echo " "
fic=$1 # nom du fichier
day=$2 # jour recherche
error=$3 # chaine erreur
#fic=/data/mysql/databases/pdtb2.err
#day=140114
#error=ERROR
echo "File : $fic"
echo "day : $day"
echo "error : $error"
nbligne=`cat $fic | wc -l`
echo "nom de lignes dans le fichier log : " $nbligne
numligne=`grep -n "$day" $fic |head -1 | awk -F ':' '{print $1}'`
if [ "x$numligne" == "x" ]; then
 echo "Pas d erreur trouvee"
 exit 0
else
 echo "Erreur trouvee en ligne : " $numligne
fi
# on compte le nombre d'erreurs trouvees et on affiche les 5 lignes suivantes du log
cpt=`tail -n +$numligne $fic | grep -C 5 $error |wc -l`
if [ $cpt == 0 ]; then
 # si pas d'erreur on sort
 exit 0
else
 # On affiche les erreur pour le log Vtom
 tail -n +$numligne $fic | grep -C 5 $error
 exit $cpt
fi

zab_mem_free.sh

#!/bin/bash
#-------------------------------------------
# Retourne le pourcentage de memoire dispo
#-------------------------------------------
mem_tot=`free | grep Mem: | awk '{print $2}'`
swap_free=`free | grep cache: | awk '{print $4}'`
memoire_disp=`echo " scale=2; $swap_free / $mem_tot * 100" | bc -l`
echo $memoire_disp

purge_file.sh

#!/bin/bash
# ==================================================
# Nom : purge_file.sh
# Objet : purge de fichier
# Auteur : FAIVELEY - DIGORA
# Cree le : 01/01/2010
# Modifié par : EF le 23/02/2012
# Syntaxe : purge_file.sh repertoire_cible nb_de_jours
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 repertoire_cible nb_de_jours"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 3 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# ----------
# Traitement
# ----------
w_rep_purge=$1
w_jour_purge=$2
w_extension=$3
echo w_rep_purge = $1
echo w_jour_purge = $2
echo w_extension = $3
w_prog=`basename $0 .sh`
w_date=$(date '+%Y_%m_%d_%H_%M_%S')
w_log_dest=/exploit/logs
w_log_file=${w_log_dest}/${w_date}_${w_prog}.log
echo " "
echo fichier log : $w_log_file
w_rep_purge=`dirname ${1}/toto`
{
echo `date +"%Y-%m-%d %H:%M:%S"` "- Debut purge du repertoire [${w_rep_purge}] pour les fichiers modifies il y a [${w_jour_purge}] jours ..."
# Recherche et supression des fichiers dans le rep w_rep_purge et qui ont ete modifies il y a $w_jour_purge jours
#
# ------ Modifié + par : EF le 23/02/2012
# ------ on traite tous les extensions de fichier.
#
#if [ "${w_rep_purge}" = "${w_log_dest}" ]
#then
# for v_fic in `find ${w_rep_purge}/ -type f -mtime ${w_jour_purge} -name "*.e"`
# do
# echo " - Suppression du fichier [${v_fic}] ..."
# rm -f ${v_fic}
# done
# for v_fic in `find ${w_rep_purge}/ -type f -mtime ${w_jour_purge} -name "*.o"`
# do
# echo " - Suppression du fichier [${v_fic}] ..."
# rm -f ${v_fic}
# done
# for v_fic in `find ${w_rep_purge}/ -type f -mtime ${w_jour_purge} -name "*.${w_extension}"`
# do
# echo " - Suppression du fichier [${v_fic}] ..."
# rm -f ${v_fic}
# done
#else
# for v_fic in `find ${w_rep_purge}/ -type f -mtime ${w_jour_purge} -name "${w_extension}"`
 for v_fic in `find ${w_rep_purge}/ -type f -mtime ${w_jour_purge} -name "*.*"`
 do
 echo " - Suppression du fichier [${v_fic}] ..."
 rm -f ${v_fic}
 done
#fi
# Modifié - par : EF le 23/02/2012
echo `date +"%Y-%m-%d %H:%M:%S"` "- Fin purge du repertoire [${w_rep_purge}] !"
} >${w_log_file} 2>&1
# Pause de 10 secondes : NE PAS SUPPRIMER
sleep 10
cat $w_log_file
exit

purge_dir.sh

#!/bin/bash
w_rep_purge=$1
w_jour_purge=$2
echo w_rep_purge = $1
echo w_jour_purge = $2
w_date=$(date '+%Y_%m_%d_%H_%M_%S')
w_log_dest=/exploit/logs
w_log_file=${w_log_dest}/${w_date}_${w_prog}.log
echo " "
echo fichier log : $w_log_file
echo " Espaces disque avant purge"
df /dev/sda1
echo " "
w_rep_purge=`dirname ${1}/toto`
{
echo `date +"%Y-%m-%d %H:%M:%S"` "- Debut purge du repertoire [${w_rep_purge}] pour les dossiers modifies il y a [${w_jour_purge}] jours ..."
# Recherche et supression des dossiers dans le rep w_rep_purge et qui ont ete modifies il y a $w_jour_purge jours
 for v_dos in `find ${w_rep_purge}/ -type d -mtime ${w_jour_purge} `
 do
 echo " - Suppression du dossier [${v_dos}] ..."
 rm -f -R ${v_dos}
 done
echo `date +"%Y-%m-%d %H:%M:%S"` "- Fin purge du repertoire [${w_rep_purge}] !"
} >${w_log_file} 2>&1
echo " "
cat ${w_log_file}
echo " "
echo " Espaces disque apres purge"
df /dev/sda1root

process_check.sh

#!/bin/bash
# ========================================================
# Objet : verification de l'etat d'un process
# Auteur : E.Fougere
# Cree le : 15/05/2012
# =======================================================
w_process=$1
echo Process : $w_process
#v_res=`grep "${w_process}:" | wc -l`
v_res=`ps -ef |grep ${w_process} | grep -v grep | wc -l`
v_res=`expr ${v_res}`
#echo $v_res
if [ ${v_res} -eq 0 ]
then
 echo "==================================================================================="
 echo "ERREUR : Process [${w_process}] inexistant !"
 echo "==================================================================================="
 exit 1
fi
if [ ${v_res} -ne 0 ]
then
 echo "==================================================================================="
 echo "PAS d'ERREUR : Process [${w_process}] existant "
 echo "==================================================================================="
 exit 0
fi

lpz_sap_m3_run_12.sh

#!/bin/sh
# Parametre 1 : environnement sur lequel seront chargees les donnees
# Parametre 2 : nom du fichier utilise pour l'initialisation du refentiel ou "integration" pour le mode normal (apres une initialisation.
# exemple de nom de fichier : LPZ_SAPM3_210510_1.zip (le fichier doit se trouver dans le repertoire : ftp.faiveley.com/LpzXM3/input)
echo "Environnement : "${1}
echo "Mode d'execution : "${2}
echo ""
# Sauvegarde des fichiers avant traitement
dt_dir=`date +"%Y_%m_%d_%H%M%S"`
dir_save=sauve_av_traitement_$dt_dir
cd /data/talend/repository/${1}
mkdir $dir_save
cp *.* $dir_save
sleep 5
sh /data/talend/jobs/LPZ_SAP_M3_INTEGRATION_1.2/LPZ_SAP_M3_INTEGRATION/LPZ_SAP_M3_INTEGRATION_run.sh ${1} ${2}
err_sh=$?
echo "Valeur err_sh : "$err_sh
echo ""
dt_fin=`date +"%A %d/%m/%Y - %H:%M:%S"`
echo $dt_fin
echo ""
if [ $err_sh -eq 0 ] ; then
${ABM_BIN}/tmail -c ${ABM_BIN}/tmail.ini -to ${3} -sub "DCC : Integration SAP - M3 env: ${1} - OK" -msg "
----------------------------- VTOM MESSAGE OK ---------------------------------------
The scheduler Vtom has successfully completed the process of Talend integration of SAP-LPZ data in M3 (${1}).
Please verify log file you received from Talend for any functional failure.
Best Regards.
------------------------------ END OF VTOM MESSAGE -----------------------------------------" -att $TOM_LOG.o\;$TOM_LOG.e
else
${ABM_BIN}/tmail -c ${ABM_BIN}/tmail.ini -to ${3} -cc ${4} -sub "ERROR - Integration SAP - M3 env: ${1} - ERROR" -msg "
******************* VTOM MESSAGE ERROR ***********************
The scheduler Vtom has completed with error the process of Talend integration of SAP-LPZ data in M3 (${1}).
Please verify log file you received from Talend for any functional failure.
Best Regards.
******************* END OF VTOM MESSAGE ERROR***********************" -att $TOM_LOG.o\;$TOM_LOG.e
err_sh=1
fi
exit $err_sh

chk_fic_sap_m3_new.sh

#!/bin/sh -vx

date_fic=`date +%d%m%y`
echo « date : « $date_fic
echo «  »

nom_fic= »LPZ_SAPM3_ »$date_fic »_1.zip »
echo « nom du fichier : « $nom_fic
echo «  »
cd /exploit/scripts

HOST=’filetransfert.faiveleytransport.com’
PORT=’21’
USER=’$1′
PASSWD=’$2′

ftp -i -n $HOST $PORT << END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd lpzxm3
cd In
bin
get $nom_fic
quit
END_SCRIPT

test -s $nom_fic
fic=$?
if [ $fic -eq 0 ] ; then
${ABM_BIN}/tmail -c ${ABM_BIN}/tmail.ini -to ${1} -sub « DCC : SAP file on filetransfert.faiveleytransport.com OK » -msg  »
Dear Dietmar,

Your file $nom_fic is now on our ftp server : filetransfert.faiveleytransport.com.

Best Regards.
IT Faiveley Team »

rm $nom_fic

else
${ABM_BIN}/tmail -c ${ABM_BIN}/tmail.ini -to ${1} -cc ccosupport@faiveley-test.com -sub « ERROR : SAP file on filetransfert.faiveleytransport.com NOT OK » -msg  »
Dear Dietmar,

We have not received your file from SAP on our ftp server (filetransfert.faiveleytransport.com) or the file is empty, today.

Best Regards.
IT Faiveley Team »;
fi

exit $fic

backup_des_fichiers.sh

# Récupération des fichiers avant traitement
echo Environnement : ${1}
echo Dossier de sauvegarde : ${2}

echo Contenu du dossier /data/talend/repository/${1} avant effacement
cd /data/talend/repository/${1}
ls -ltra
# Cette commande ne supprime pas les sous dossier
rm *.*
echo Contenu du dossier de sauvegarde /data/talend/repository/${1}/${2}
cd /data/talend/repository/${1}/${2}
ls -ltra
cp *.* ..
echo Contenu du dossier /data/talend/repository/${1} après récupération
cd ..
ls -ltra