ora_switch_logfile.sh

#!/bin/bash
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
v_res=`grep "${w_instance}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees ${w_instance} inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}
echo $ORACLE_SID
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
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}_${w_instance}.log;
sqlplus /nolog <<EOSQL >>$w_log_file 2>&1
WHENEVER SQLERROR EXIT SQL.SQLCODE
connect / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
exit

ora_compilation.sh

#!/bin/bash
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
v_res=`grep "${w_instance}" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees [${w_instance}] inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
echo "SID=${w_instance}"
export ORACLE_SID=${w_instance}
ls /soft/oracle/db102/rdbms/admin/utlrp.sql
err_fic=$?
if [ "${err_fic}" != "0" ]
then
 echo Fichier absent.
 exit ${err_fic}
fi
export ORACLE_SID=$1
echo "recompile tous les objets invalides" ${ORACLE_SID}
sqlplus /nolog <<EOF
 connect / as sysdba
 WHENEVER SQLERROR EXIT SQL.SQLCODE
 SELECT owner#,name,status,ctime,mtime,stime FROM obj$ WHERE status IN (4, 5, 6);
start /soft/oracle/db102/rdbms/admin/utlrp.sql
SELECT job_name FROM dba_scheduler_running_jobs WHERE job_name like 'UTL_RECOMP_SLAVE_%';
exit
 EOF
exit ${err_sql}

stop_database.sh

#!/bin/bash
# ==================================================
# Nom : start_database.sh
# Objet : arret d'une base de donnees
# Cree le : 28/01/2010
# Syntaxe : start_database.sh database_name
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
v_res=`grep "${w_instance}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees ${w_instance} inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
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}_${w_instance}.log;
sqlplus /nolog <<EOSQL >>$w_log_file 2>&1
connect / as sysdba
shutdown immediate;
exit
EOSQL

start_database.sh

#!/bin/bash
# ==================================================
# Nom : start_database.sh
# Objet : demarrage d'une base de donnees
# Cree le : 28/01/2010
# Syntaxe : start_database.sh database_name
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
v_res=`grep "${w_instance}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees ${w_instance} inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}
echo $ORACLE_SID
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
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}_${w_instance}.log;
sqlplus /nolog <<EOSQL >>$w_log_file 2>&1
connect / as sysdba
startup;
select NAME, CREATED,LOG_MODE,OPEN_MODE from v\$database;
exit
EOSQL

 

ora_arch_logfile.sh

#!/bin/bash
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
v_res=`grep "${w_instance}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees ${w_instance} inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}
echo $ORACLE_SID
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
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}_${w_instance}.log;
sqlplus /nolog <<EOSQL >>$w_log_file 2>&1
WHENEVER SQLERROR EXIT SQL.SQLCODE
connect / as sysdba
ALTER SYSTEM ARCHIVE LOG CURRENT;
exit

sauve_cold.sh

#!/bin/bash
# ==================================================
# Nom : sauve_cold.sh
# Objet : sauvegarde RMAN a froid d'une base complete
# Auteur : S. GOURGAND - DIGORA
# Cree le : 27/01/2010
# Syntaxe : sauve_cold.sh database_name
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
echo "w_instance : "$1
[ "${HOSTNAME}" = "king" -o "${HOSTNAME}" = "king.faiveley.com" ] && w_num=1
[ "${HOSTNAME}" = "kong" -o "${HOSTNAME}" = "kong.faiveley.com" ] && w_num=2
[ "${HOSTNAME}" = "ping" -o "${HOSTNAME}" = "ping.faiveleytransport.local" ] && w_num=3
[ "${HOSTNAME}" = "pong" -o "${HOSTNAME}" = "pong.faiveleytransport.local" ] && w_num=4
v_res=`grep "${w_instance}${w_num}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees ${w_instance} inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}${w_num}
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
export NLS_DATE_FORMAT="DD/MM/YYYY HH24:MI:SS"
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}_${w_instance}.log;
rman <<EORMAN >${w_log_file} 2>&1
connect target / ;
connect catalog rman/rman@ref_rman;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
startup force dba;
shutdown immediate;
startup mount;
backup tag 'database cold' database plus archivelog tag 'archives cold';
alter database open;
delete noprompt obsolete;
report need backup;
list backup summary;
exit
EORMAN
# Ajout 08/04/2010 : Envoi du fichier de traces par mail
# ------------------------------------------------------
w_host=`basename $HOSTNAME .faiveley.com`
w_host=`basename ${w_host} .faiveleytransport.local | tr [a-z] [A-Z]`
mail -s "${w_host} : Sauvegarde a froid de la base ${w_instance}" u1_info_exploit@faiveleytransport.com <${w_log_file}
# Ajout 31/03/2011 : Traitement des anomalies pour VTOM
# -----------------------------------------------------
v_res=`grep "^RMAN-" ${w_log_file} | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -gt 0 ]
then
 echo +----------------------------+
 echo ! DEBUT DU FICHIER DE TRACES !
 echo +----------------------------+
 cat ${w_log_file}
 echo +--------------------------+
 echo ! FIN DU FICHIER DE TRACES !
 echo +--------------------------+
 exit 1
else
 exit 0
fi

sauve_hot.sh

#!/bin/bash
# ==================================================
# Nom : sauve_backup.sh
# Objet : sauvegarde RMAN d'une base complete
# Auteur : S. GOURGAND - DIGORA
# Cree le : 28/01/2010
# Syntaxe : sauve_backup.sh database_name
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0 database_name"
}
# --------------------------
# Verification de la syntaxe
# --------------------------
if [ $# -ne 1 ]
then
 echo "=================================================="
 echo "ERREUR : Nombre d'arguments incorrects !"
 syntaxe
 echo "=================================================="
 exit 1
fi
# --------------------------
# Verification des arguments
# --------------------------
w_instance=$1
[ "${HOSTNAME}" = "king" -o "${HOSTNAME}" = "king.faiveley.com" ] && w_num=1
[ "${HOSTNAME}" = "kong" -o "${HOSTNAME}" = "kong.faiveley.com" ] && w_num=2
[ "${HOSTNAME}" = "ping" -o "${HOSTNAME}" = "ping.faiveleytransport.local" ] && w_num=3
[ "${HOSTNAME}" = "pong" -o "${HOSTNAME}" = "pong.faiveleytransport.local" ] && w_num=4
v_res=`grep "${w_instance}${w_num}:" /etc/oratab | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -eq 0 ]
then
 echo "=================================================="
 echo "ERREUR : Base de donnees [${w_instance}] inexistante !"
 syntaxe
 echo "=================================================="
 exit 1
fi
export ORACLE_SID=${w_instance}${w_num}
echo instance : ${ORACLE_SID}
# export NLS_DATE_FORMAT=YYYY.MM.DD.HH24.MI.SS
export NLS_DATE_FORMAT="DD/MM/YYYY HH24:MI:SS"
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}_${w_instance}.log;
rman <<EORMAN >${w_log_file} 2>&1
connect target / ;
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
backup incremental level 0 tag 'database level 0' database plus archivelog tag 'archives level 0';
delete noprompt obsolete;
report need backup;
list backup summary;
exit
EORMAN
# Ajout 08/04/2010 : Envoi du fichier de traces par mail
# ------------------------------------------------------
w_host=`basename $HOSTNAME .faiveley.com`
w_host=`basename ${w_host} .faiveleytransport.local | tr [a-z] [A-Z]`
mail -s "${w_host} : Hot Backup Database ${w_instance}" nicolas.lamotte@faiveleytransport.com <${w_log_file}
# Ajout 31/03/2011 : Traitement des anomalies pour VTOM
# -----------------------------------------------------
v_res=`grep "^RMAN-" ${w_log_file} | wc -l`
v_res=`expr ${v_res}`
if [ ${v_res} -gt 0 ]
then
 echo +----------------------------+
 echo ! DEBUT DU FICHIER DE TRACES !
 echo +----------------------------+
 cat ${w_log_file}
 echo +--------------------------+
 echo ! FIN DU FICHIER DE TRACES !
 echo +--------------------------+
 exit 1
else
 exit 0
fi

ora_alertlog.sh

#!/bin/sh
echo "----------------------------------------------"
echo " Recherche des erreurs dans les log"
echo "----------------------------------------------"
echo " "
fic=$1 # nom du fichier
month=$2 # mois recherché
year=$3 # année recherchée
day=$4 # jour recherché
error="$5" # chaine erreur
#fic=/soft/oracle/admin/BIPROD/bdump/alert_BIPROD.log
#month=DEC
#year=2013
#day=30
#error="ORA-"
# On transforme le mois de MAJUSCULE en minuscule puis on passe la première lettre en Majuscule
month=`echo $month|tr "A-Z" "a-z"|sed 's/^./\u&/'`
day=`echo $day | tr "0" " " | sed 's/^./\u&/'`
echo "File : $fic"
echo "month : $month"
echo "year : $year"
echo "day : $day"
echo "error : $error"
nbligne=`wc $fic | awk '{print $1}'`
echo "nom de lignes dans le fichier log : " $nbligne
echo "grep -n '... $month $day ........ $year' $fic |head -1 | awk -F ':' '{print $1}'"
numligne=`grep -n "... $month $day ........ $year" $fic |head -1 | awk -F ':' '{print $1}'`
echo "Numero de la ligne de la date demandée : " $numligne
# on compte le nombre d'erreurs trouvées et on affiche les 5 lignes suivantes du log
echo "tail -n +$numligne $fic| grep $error |wc -l"
cpt=`tail -n +$numligne $fic| grep -v WARNING |grep $error |wc -l`
if [ $cpt == 0 ]; then
 # si pas d'erreur on sort
 exit 0
else
 # On affiche les erreur pour le log Vtom
 echo "tail -n +$numligne $fic | grep -C 5 $error"
 tail -n +$numligne $fic |grep -v WARNING| grep -C 5 $error
 exit $cpt
fi

stop_server.sh

#!/bin/bash
hostname
uptime
echo ===== arret Oracle =====
echo ----- ps oracle ------
ps -ef | grep listener | grep -v grep
ps -ef | grep smon | grep -v grep
echo ----- uptime
uptime
echo ----- stop database
su -l ora102 -l /exploit/scripts/stop_oracle.sh
echo ===== arret Mysql======
echo ----- ps mysqld ------
ps -ef | grep mysqld | grep -v grep
echo ----- uptime
uptime
echo ----- stop database
/exploit/scripts/my_stop_database.sh
echo ----- tempo 600
sleep 600
echo ----- check process oracle
ps -ef | grep listener | grep -v grep
ps -ef | grep smon | grep -v grep
echo ----- check process mysql
ps -ef | grep mysqld | grep -v grep
echo ----- halt
halt

	

start_server.sh

#!/bin/bash
hostname
echo ===== start Oracle =====
echo ----- start database
su -l ora102 -l /exploit/scripts/start_oracle.sh
echo ----- ps oracle ------
ps -ef | grep lsnr | grep -v grep
ps -ef | grep smon | grep -v grep
echo ===== start Mysql======
echo ----- ps mysqld ------
ps -ef | grep mysqld | grep -v grep
echo ----- uptime
uptime
echo ----- start database
/exploit/scripts/my_start_database.sh
echo ----- check process mysql
ps -ef | grep mysqld | grep -v grep

stop_listener.sh

#!/bin/bash
# ==================================================
# Nom : stop_listener.sh
# Objet : arret du listener
# Cree le : 28/01/2010
# Syntaxe : stop_listener.sh
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0"
}
lsnrctl status
lsnrctl stop

start_listener.sh

#!/bin/bash
# ==================================================
# Nom : start_listener.sh
# Objet : demarrage du listener
# Cree le : 28/01/2010
# Syntaxe : start_listener.sh
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0"
}
lsnrctl start
lsnrctl status

stop_oracle.sh

#!/bin/bash
# ==================================================
# Nom : stop_oracle.sh
# Objet : arret des listeners et bases de donnees
# Cree le : 28/01/2010
# Syntaxe : stop_oracle.sh
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0"
}
/exploit/scripts/stop_listener.sh
/exploit/scripts/stop_database.sh KTP
# /exploit/scripts/stop_database.sh STRPRD
/exploit/scripts/stop_database.sh KTPTST
/exploit/scripts/stop_database.sh HYPDEV
/exploit/scripts/stop_database.sh HYPPROD
/exploit/scripts/stop_database.sh EPS
/exploit/scripts/stop_database.sh BIPROD
/exploit/scripts/stop_database.sh ABEL
/exploit/scripts/stop_database.sh BITEST
/exploit/scripts/stop_database.sh SISDEV

start_oracle.sh

#!/bin/bash
# ==================================================
# Nom : start_oracle.sh
# Objet : demarrage des listeners et bases de donnees
# Cree le : 28/01/2010
# Syntaxe : start_oracle.sh
# ==================================================
# ----------------------------------
# Fonction d'affichage de la syntaxe
# ----------------------------------
syntaxe()
{
 echo "Usage : $0"
}
sh /exploit/scripts/start_listener.sh
sh /exploit/scripts/start_database.sh KTP
# sh /exploit/scripts/start_database.sh STRPRD
sh /exploit/scripts/start_database.sh KTPTST
sh /exploit/scripts/start_database.sh HYPDEV
sh /exploit/scripts/start_database.sh HYPPROD
sh /exploit/scripts/start_database.sh EPS
sh /exploit/scripts/start_database.sh BIPROD
sh /exploit/scripts/start_database.sh ABEL
sh /exploit/scripts/start_database.sh BITEST
sh /exploit/scripts/start_database.sh SISDEV

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