mysqladmin -pmotdepasse shutdown
Category: Linux
my_start_database.sh
mysqld_safe --user=mysql &
my_SISCAT_reload.sh
database=SISCAT dumpfile=/exploit/dumps/my-dump-SISCAT.sql
mysqladmin -pmotdepasse drop $database; mysqladmin -pmotdepasse create $database; mysql -pmotdepasse --database $database < $dumpfile
my_exp_SISCAT_pdtb2.sh
w_date=$(date '+%Y_%m_%d_%H_%M_%S')
#mysqldump -h pdtb2.ft.grp -u 64serviceprd -pmotdepasse --log-error=/exploit/logs/my-dump-SISCAT-${w_date}.log SISCAT > /exploit/dumps/my-dump-SISCAT.sql
mysqldump -h pdtb2.ft.grp -u 64serviceprd -pmotdepasse SISCAT > /exploit/dumps/my-dump-SISCAT.sql
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_drop_database_mig.sh
mysqladmin -pmotdepass drop FT_DATAMART_PROD;
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_view_mig.sh
#!/bin/bash file=/exploit/scripts/my_alter_view_mig.sql mysql -pzsxedc <$file
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_proc_mem.sh
#!/bin/bash
proc=$1
ps ax -eo %mem,args --sort:%mem |grep -v grep | grep $proc | awk '{s=s+$i }; END{print s}'
zab_proc_cpu.sh
#!/bin/bash proc=$1
ps ax -eo %cpu,args --sort:%cpu |grep -v grep | grep $proc | awk '{s=s+$i }; END{print s}'
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