mise à jour v2
Grosse mise à jour : - style moderne des tableaux et code - code structuré et factorisé - sql et sh affinés
This commit is contained in:
150
sh/09_os_info.sh
150
sh/09_os_info.sh
@@ -1,122 +1,100 @@
|
||||
# faire des commandes pour AIX et pour Linux
|
||||
#!/bin/bash
|
||||
|
||||
# Importe les fonctions utilitaires
|
||||
source "$(dirname "$0")/utils.sh"
|
||||
|
||||
# --- Script principal ---
|
||||
|
||||
os_type=$(uname -s)
|
||||
|
||||
echo "<h2>Bases de données en cours d'exécution :</h2>"
|
||||
echo "<pre>"
|
||||
ps -ef | grep pmon | grep -v grep
|
||||
echo "</pre>"
|
||||
print_h2 "Bases de données en cours d'exécution"
|
||||
run_and_print "ps -ef | grep pmon | grep -v grep"
|
||||
|
||||
echo "<h2>Listeners en cours d'exécution :</h2>"
|
||||
echo "<pre>"
|
||||
ps -ef | grep tnslsnr | grep -v grep
|
||||
echo "</pre>"
|
||||
print_h2 "Listeners en cours d'exécution"
|
||||
run_and_print "ps -ef | grep tnslsnr | grep -v grep"
|
||||
|
||||
echo "<h2>Statut du listener :</h2>"
|
||||
# ps -ef | grep tnslsnr | egrep -i "LISTENER_${ORACLE_SID}" | grep -v grep | while read l
|
||||
ps -ef | grep tnslsnr | egrep -i " LISTENER |${ORACLE_SID}" | grep -v grep | while read l
|
||||
do
|
||||
# Récupérer le chemin ORACLE_HOME à partir de la sortie de ps -ef
|
||||
# ---- La commande grep -o ne fonctionne pas sur AIX, on la remplace par perl -lne
|
||||
# binary_path=$(echo $l | grep -o '/[^ ]*' | sed 's#/bin/tnslsnr##')
|
||||
binary_path=$(echo $l | perl -lne 'print $1 if /(\S*tnslsnr\S*)/' | sed 's#/bin/tnslsnr##')
|
||||
# Extraire le nom du listener
|
||||
# listener_name=$(echo $l | grep -o 'tnslsnr [^ ]*' | sed 's/tnslsnr //')
|
||||
listener_name=$(echo $l | perl -lne 'print $1 if /\btnslsnr\s+(\S+)/' | sed 's/tnslsnr //')
|
||||
# Construire la commande lsnrctl status
|
||||
lsnrctl_command="$binary_path/bin/lsnrctl status $listener_name"
|
||||
# exécuter la commande
|
||||
echo "<br><pre>"
|
||||
echo $lsnrctl_command
|
||||
echo export TNS_ADMIN=$binary_path/network/admin
|
||||
export TNS_ADMIN=$binary_path/network/admin
|
||||
eval "$lsnrctl_command"
|
||||
echo "</pre><br>"
|
||||
print_h2 "Statut du listener : ${listener_name}"
|
||||
# Boucle pour le statut du listener, car elle est plus complexe
|
||||
ps -ef | grep tnslsnr | egrep -i " LISTENER |${ORACLE_SID}" | grep -v grep | while read -r l; do
|
||||
binary_path=$(echo "$l" | perl -lne 'print $1 if /(\S*tnslsnr\S*)/' | sed 's#/bin/tnslsnr##')
|
||||
listener_name=$(echo "$l" | perl -lne 'print $1 if /\btnslsnr\s+(\S+)/' | sed 's/tnslsnr //')
|
||||
|
||||
if [ -n "$binary_path" ] && [ -n "$listener_name" ]; then
|
||||
export TNS_ADMIN="$binary_path/network/admin"
|
||||
lsnrctl_command="$binary_path/bin/lsnrctl status $listener_name"
|
||||
# echo "<b>Listener: ${listener_name}</b>"
|
||||
run_and_print "$lsnrctl_command"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "<h2>Uptime :</h2>"
|
||||
echo "<pre>"
|
||||
uptime
|
||||
echo "</pre>"
|
||||
print_h2 "Uptime"
|
||||
run_and_print "uptime"
|
||||
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
echo "<h2>Espace disque (lsfs) :</h2>"
|
||||
echo "<pre>"
|
||||
lsfs
|
||||
echo "</pre>"
|
||||
print_h2 "Espace disque (lsfs)"
|
||||
run_and_print "lsfs"
|
||||
;;
|
||||
Linux)
|
||||
echo "<h2>Contenu du fichier /etc/fstab :</h2>"
|
||||
echo "<pre>"
|
||||
cat /etc/fstab | egrep -v '^#|^$'
|
||||
echo "</pre>"
|
||||
print_h2 "Contenu du fichier /etc/fstab"
|
||||
run_and_print "cat /etc/fstab | egrep -v '^#|^$'"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "<h2>Contenu du contab du compte oracle :</h2>"
|
||||
echo "<pre>"
|
||||
crontab -l
|
||||
echo "</pre>"
|
||||
print_h2 "Contenu du contab du compte oracle"
|
||||
run_and_print "crontab -l"
|
||||
|
||||
echo "<h2>Limites de l'utilisateur "oracle" (ulimit -a) :</h2>"
|
||||
echo "<pre>"
|
||||
ulimit -a | sort
|
||||
echo "</pre>"
|
||||
print_h2 "Limites de l'utilisateur (ulimit -a)"
|
||||
run_and_print "ulimit -a | sort"
|
||||
|
||||
# espace disque en fonction de l'OS
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
echo "<h2>Espace disque (df -g) :</h2>"
|
||||
echo "<pre>"
|
||||
df -g
|
||||
echo "</pre>"
|
||||
print_h2 "Espace disque (df -g)"
|
||||
run_and_print "df -g"
|
||||
;;
|
||||
Linux)
|
||||
echo "<h2>Espace disque (df -h) :</h2>"
|
||||
echo "<pre>"
|
||||
df -h
|
||||
echo "</pre>"
|
||||
print_h2 "Espace disque (df -h)"
|
||||
run_and_print "df -h"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
case "$os_type" in
|
||||
Linux)
|
||||
echo "<h2>Liste des disques disponibles (lsblk) :</h2>"
|
||||
echo "<pre>"
|
||||
lsblk
|
||||
echo "</pre>"
|
||||
print_h2 "Liste des disques disponibles (lsblk)"
|
||||
run_and_print "lsblk"
|
||||
|
||||
echo "<h2>Taille mémoire en Mo (free -m) :</h2>"
|
||||
echo "<pre>"
|
||||
free -m
|
||||
echo "</pre>"
|
||||
print_h2 "Taille mémoire en Mo (free -m)"
|
||||
run_and_print "free -m"
|
||||
|
||||
echo "<h2>Caractéristiques CPU (lscpu) :</h2>"
|
||||
echo "<pre>"
|
||||
lscpu
|
||||
echo "</pre>"
|
||||
print_h2 "Caractéristiques CPU (lscpu)"
|
||||
run_and_print "lscpu"
|
||||
|
||||
echo "<h2>Les 50 dernières erreur dans /var/log/messages :</h2>"
|
||||
if sudo -l &> /dev/null ; then
|
||||
# L'utilisateur a les droits sudo. on continue
|
||||
echo "<pre>"
|
||||
sudo cat /var/log/messages | egrep -i 'error|failed' | tail -50
|
||||
echo "</pre>"
|
||||
else
|
||||
echo "<pre>"
|
||||
echo "L'utilisateur n'a les droits pour lire les fichiers log."
|
||||
echo "</pre>"
|
||||
fi
|
||||
print_h2 "Statistiques VM (vmstat 2 20)"
|
||||
run_and_print "vmstat 2 20"
|
||||
|
||||
print_h2 "Top 10 processus par utilisation CPU (ps --width 150)"
|
||||
run_and_print "ps -eo pid,user,%cpu,%mem,vsz,rss,tty,stat,start,time,command --sort=-%cpu --width 1000 | head -n 17 | cut -c 1-180"
|
||||
|
||||
print_h2 "Derniers messages du noyau (dmesg -T | tail -n 30)"
|
||||
if sudo -ln &> /dev/null; then
|
||||
run_and_print "sudo dmesg -T | tail -n 30"
|
||||
else
|
||||
echo "<pre>L'utilisateur n'a pas les droits sudo pour exécuter dmesg.</pre>"
|
||||
fi
|
||||
|
||||
print_h2 "Les 30 dernières erreurs dans /var/log/messages"
|
||||
if sudo -ln &> /dev/null; then
|
||||
run_and_print "sudo cat /var/log/messages | egrep -i 'error|failed' | tail -30"
|
||||
else
|
||||
echo "<pre>L'utilisateur n'a pas les droits sudo pour lire les fichiers log.</pre>"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
echo "<h2>Configuration système (prtconf) :</h2>"
|
||||
echo "<pre>"
|
||||
prtconf
|
||||
echo "</pre>"
|
||||
print_h2 "Configuration système (prtconf)"
|
||||
run_and_print "prtconf"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
# faire des commandes pour AIX et pour Linux
|
||||
os_type=$(uname -s)
|
||||
|
||||
# Function to execute command and format output
|
||||
execute_command() {
|
||||
command="$1"
|
||||
output="$(eval "$command" 2>&1)" # Capture both stdout and stderr using eval
|
||||
# Print the command and its output in the specified format
|
||||
echo "--- Commande ---"
|
||||
echo "$command"
|
||||
echo "--- Résultat ---"
|
||||
echo "$output"
|
||||
echo "--- Fin Bloc ---"
|
||||
}
|
||||
|
||||
execute_command "ps -ef | grep pmon | grep -v grep"
|
||||
execute_command "ps -ef | grep tnslsnr | grep -v grep"
|
||||
|
||||
# Listener status
|
||||
ps -ef | grep tnslsnr | egrep -i " LISTENER |${ORACLE_SID}" | grep -v grep | while read l
|
||||
do
|
||||
binary_path=$(echo $l | perl -lne 'print $1 if /(\S*tnslsnr\S*)/' | sed 's#/bin/tnslsnr##')
|
||||
listener_name=$(echo $l | perl -lne 'print $1 if /\btnslsnr\s+(\S+)/' | sed 's/tnslsnr //')
|
||||
lsnrctl_command="$binary_path/bin/lsnrctl status $listener_name"
|
||||
export TNS_ADMIN=$binary_path/network/admin
|
||||
execute_command "$lsnrctl_command"
|
||||
done
|
||||
|
||||
execute_command "uptime"
|
||||
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
execute_command "lsfs"
|
||||
;;
|
||||
Linux)
|
||||
execute_command "cat /etc/fstab | egrep -v '^#|^$'"
|
||||
;;
|
||||
esac
|
||||
|
||||
execute_command "crontab -l"
|
||||
execute_command "ulimit -a | sort"
|
||||
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
execute_command "df -g"
|
||||
;;
|
||||
Linux)
|
||||
execute_command "df -h"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$os_type" in
|
||||
Linux)
|
||||
execute_command "lsblk"
|
||||
execute_command "free -m"
|
||||
execute_command "lscpu"
|
||||
if sudo -l &> /dev/null ; then
|
||||
execute_command "sudo cat /var/log/messages | egrep -i 'error|failed' | tail -50"
|
||||
else
|
||||
echo "--- Commande ---"
|
||||
echo "sudo cat /var/log/messages | egrep -i 'error|failed' | tail -50"
|
||||
echo "--- Résultat ---"
|
||||
echo "L'utilisateur n'a les droits pour lire les fichiers log."
|
||||
echo "--- Fin Bloc ---"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$os_type" in
|
||||
AIX)
|
||||
execute_command "prtconf"
|
||||
;;
|
||||
esac
|
||||
@@ -1,25 +1,40 @@
|
||||
# /etc/oratab
|
||||
echo "<h2>Contenu du fichier /etc/oratab :</h2>"
|
||||
echo "<pre>"
|
||||
cat /etc/oratab | egrep -v "^$|^#"
|
||||
echo "</pre>"
|
||||
#!/bin/bash
|
||||
|
||||
# inventory.xml
|
||||
echo "<h2>Contenu du fichier Inventory.xml :</h2>"
|
||||
echo "<pre>"
|
||||
ORA_INVENTORY=$(cat /etc/oraInst.loc | grep inventory_loc | cut -d= -f2)
|
||||
cat $ORA_INVENTORY/ContentsXML/inventory.xml | grep "<HOME NAME=" | awk '{print $2 " " $3}'
|
||||
echo "</pre>"
|
||||
# Importe les fonctions utilitaires
|
||||
source "$(dirname "$0")/utils.sh"
|
||||
|
||||
# opatch
|
||||
echo "<h2>Niveau de patch des ORACLE_HOME (opatch lspatches) :</h2>"
|
||||
cat /etc/oratab | egrep -v "^$|^#" | cut -d: -f2 | sort -u | while read oh
|
||||
do
|
||||
echo "<pre>"
|
||||
echo "ORACLE_HOME="$oh
|
||||
echo ""
|
||||
export ORACLE_HOME=$oh
|
||||
$oh/OPatch/opatch lspatches
|
||||
echo "</pre><br>"
|
||||
done
|
||||
# --- Script principal ---
|
||||
|
||||
print_h2 "Contenu du fichier /etc/oratab"
|
||||
run_and_print "cat /etc/oratab | egrep -v '^$|^#'"
|
||||
|
||||
print_h2 "Contenu du fichier Inventory.xml"
|
||||
# On s'assure que le fichier oraInst.loc existe et est lisible
|
||||
if [ -r /etc/oraInst.loc ]; then
|
||||
ORA_INVENTORY=$(grep inventory_loc /etc/oraInst.loc | cut -d= -f2)
|
||||
if [ -n "${ORA_INVENTORY}" ] && [ -r "${ORA_INVENTORY}/ContentsXML/inventory.xml" ]; then
|
||||
run_and_print "grep '<HOME NAME=' ${ORA_INVENTORY}/ContentsXML/inventory.xml | awk '{print \$2 \" \" \$3}'"
|
||||
else
|
||||
echo "<pre>Impossible de lire le fichier inventory.xml ou chemin non trouvé.</pre>"
|
||||
fi
|
||||
else
|
||||
echo "<pre>Fichier /etc/oraInst.loc non trouvé.</pre>"
|
||||
fi
|
||||
|
||||
print_h2 "Niveau de patch des ORACLE_HOME (opatch lspatches)"
|
||||
if [ -r "${ORA_INVENTORY}/ContentsXML/inventory.xml" ]; then
|
||||
# Utilise un `while read` pour plus de robustesse que `cat ... | while`
|
||||
while read -r line; do
|
||||
# Ignore les lignes vides ou commentées
|
||||
[[ "$line" =~ ^# ]] || [ -z "$line" ] && continue
|
||||
|
||||
oh=$(echo "$line" | cut -d: -f2 | sort -u)
|
||||
if [ -d "$oh" ]; then
|
||||
export ORACLE_HOME=$oh
|
||||
run_and_print "\"$oh/OPatch/opatch\" lspatches"
|
||||
fi
|
||||
done < <(grep -oP 'LOC="\K[^"]+' ${ORA_INVENTORY}/ContentsXML/inventory.xml)
|
||||
else
|
||||
echo "<pre>Fichier ${ORA_INVENTORY}/ContentsXML/inventory.xml non trouvé.</pre>"
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Importe les fonctions utilitaires
|
||||
source "$(dirname "$0")/utils.sh"
|
||||
|
||||
# --- Script principal ---
|
||||
|
||||
# script à exécuter si seulement dbvctl existe et une instance avec le nom de service dbv existe aussi
|
||||
|
||||
count=$(ps -ef | grep dbvctl | grep -v grep | grep ${ORACLE_SID} | wc -l)
|
||||
count=$(ps -ef | grep dbvctl | grep -v grep | grep "${ORACLE_SID}" | wc -l)
|
||||
|
||||
if [ $count -gt 0 ]; then
|
||||
if [ "$count" -gt 0 ]; then
|
||||
|
||||
echo "<h1>Configuration DBVisit</h1>"
|
||||
# les process dbvisit en cours
|
||||
echo "<h2>Process DBVisit en cours d'exécution</h2>"
|
||||
echo "<pre>"
|
||||
ps -ef | grep dbvctl | grep -v grep
|
||||
echo "</pre>"
|
||||
print_h2 "Process DBVisit en cours d'exécution"
|
||||
run_and_print "ps -ef | grep dbvctl | grep -v grep"
|
||||
|
||||
# on récupère le chemin de l'executable dbvctl
|
||||
export DBV_HOME=$(dirname $(ps -ef | grep dbvctl | grep -v grep | awk '{print $8}' | sort -u))
|
||||
export DBV_HOME=$(dirname "$(ps -ef | grep dbvctl | grep -v grep | awk '{print $8}' | sort -u)")
|
||||
# si les exacutables sont lancé avec ./dbvctl, le résultat retourné est .
|
||||
# dans ce cas on remplace par la valeur par défaut : /usr/dbvisit/standby
|
||||
if [ "$DBV_HOME" = "." ]; then
|
||||
@@ -20,18 +24,13 @@ if [ $count -gt 0 ]; then
|
||||
export DBV_HOME="/usr/dbvisit/standby"
|
||||
fi
|
||||
|
||||
# statut de la base de données
|
||||
echo "<h2>Statut de la base : ${ORACLE_SID} sur le serveur $(hostname)</h2>"
|
||||
echo "<pre>"
|
||||
${DBV_HOME}/dbvctl -d ${ORACLE_SID} -o status
|
||||
echo "</pre>"
|
||||
print_h2 "Statut de la base : ${ORACLE_SID} sur le serveur $(hostname)"
|
||||
run_and_print "${DBV_HOME}/dbvctl -d ${ORACLE_SID} -o status"
|
||||
|
||||
# on récupère le statut de la base pour exécuter la commande sur la base primaire
|
||||
db_prim=$(${DBV_HOME}/dbvctl -d ${ORACLE_SID} -o status | grep -i "read write" | wc -l)
|
||||
if [ ${db_prim} -gt 0 ]; then
|
||||
echo "<h2>Rapport de GAP DBVisit pour la base ${ORACLE_SID}</h2>"
|
||||
echo "<pre>"
|
||||
${DBV_HOME}/dbvctl -d ${ORACLE_SID} -i
|
||||
echo "</pre>"
|
||||
db_prim=$("${DBV_HOME}/dbvctl" -d "${ORACLE_SID}" -o status | grep -i "read write" | wc -l)
|
||||
if [ "${db_prim}" -gt 0 ]; then
|
||||
print_h2 "Rapport de GAP DBVisit pour la base ${ORACLE_SID}"
|
||||
run_and_print "${DBV_HOME}/dbvctl -d ${ORACLE_SID} -i"
|
||||
fi
|
||||
fi
|
||||
23
sh/30_crs.sh
23
sh/30_crs.sh
@@ -1,16 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Importe les fonctions utilitaires
|
||||
source "$(dirname "$0")/utils.sh"
|
||||
|
||||
# --- Script principal ---
|
||||
|
||||
# script à exécuter si couche grid/crs
|
||||
|
||||
count=$(ps -ef | grep ohasd | grep -v grep | wc -l)
|
||||
|
||||
if [ $count -gt 0 ]; then
|
||||
if [ "$count" -gt 0 ]; then
|
||||
|
||||
echo "<h2>Services CRS</h2>"
|
||||
# les process dbvisit en cours
|
||||
print_h2 "Services CRS"
|
||||
|
||||
# BIN_DIR=$(dirname $(ps -ef | grep ohasd.bin | grep -v grep | egrep -o '/.*ohasd\.bin'))
|
||||
# la commande egrep -o ne fonctionne pas sous AIX
|
||||
# on utilise donc la commande suivante avec awk
|
||||
BIN_DIR=$(dirname $(ps -ef | grep ohasd.bin | grep -v grep | awk '{ match($0, /\/.*ohasd\.bin/); print substr($0, RSTART, RLENGTH) }'))
|
||||
BIN_DIR=$(dirname "$(ps -ef | grep ohasd.bin | grep -v grep | awk '{ match($0, /\/.*ohasd\.bin/); print substr($0, RSTART, RLENGTH) }')")
|
||||
# explication de la commande awk :
|
||||
# - match($0, /\/.*ohasd\.bin/): Cette partie de la commande awk recherche la première occurrence
|
||||
# de la séquence "/.*ohasd.bin" dans la ligne.
|
||||
@@ -18,7 +24,10 @@ if [ $count -gt 0 ]; then
|
||||
# la position RSTART (où la correspondance commence) jusqu'à la longueur RLENGTH de la correspondance.
|
||||
# - Le résultat sera la portion de la chaîne entre le premier / et le mot "ohasd.bin".
|
||||
# - la commande dirname retourne le répertoire qui sera utilisé dans BIN_DIR
|
||||
echo "<pre>"
|
||||
${BIN_DIR}/crsctl status res -t
|
||||
echo "</pre>"
|
||||
|
||||
if [ -n "$BIN_DIR" ] && [ -x "$BIN_DIR/crsctl" ]; then
|
||||
run_and_print "${BIN_DIR}/crsctl status res -t"
|
||||
else
|
||||
echo "<pre>Impossible de trouver le répertoire d'installation CRS ou crsctl n'est pas exécutable.</pre>"
|
||||
fi
|
||||
fi
|
||||
@@ -1,35 +1,47 @@
|
||||
#!/bin/bash
|
||||
# script pour vérifier les logs des fichiers datapump et voir si des erreurs sont présentes
|
||||
|
||||
# Importe les fonctions utilitaires
|
||||
source "$(dirname "$0")/../utils.sh"
|
||||
|
||||
# --- Script principal ---
|
||||
|
||||
# EXPDP_DIR="/u04/backup" : la variable d'environnement est chargée depuis le fichier .env
|
||||
|
||||
CURRENT_DATE=$(date +%Y_%m) # date au format 2025_04
|
||||
|
||||
echo "<h2>Vérification des logs des exports Datapump</h2>"
|
||||
print_h2 "Vérification des logs des exports Datapump"
|
||||
|
||||
# vérifier si une erreur ORA- est pésente dans les fichiers logs
|
||||
echo "<h3>Vérification de la présence d'erreurs dans les logs :</h3>"
|
||||
RESULT=$(find "${EXPDP_DIR}" -iname "export_*.log" -exec grep -H "ORA-" "{}" \;)
|
||||
if [ -z "$RESULT" ]; then
|
||||
echo "<pre>Aucune erreur ORA- détectée dans les fichiers logs du mois ${CURRENT_DATE}.</pre>"
|
||||
|
||||
if [ -z "${EXPDP_DIR}" ]; then
|
||||
echo "<pre>La variable EXPDP_DIR n'est pas définie. Impossible de vérifier les logs Datapump.</pre>"
|
||||
elif [ ! -d "${EXPDP_DIR}" ]; then
|
||||
echo "<pre>Le répertoire EXPDP_DIR ('${EXPDP_DIR}') n'existe pas ou n'est pas accessible.</pre>"
|
||||
else
|
||||
echo "<pre>$RESULT</pre>"
|
||||
fi
|
||||
RESULT=$(find "${EXPDP_DIR}" -iname "export_*.log" -exec grep -H "ORA-" "{}" \;)
|
||||
if [ -z "$RESULT" ]; then
|
||||
echo "<pre>Aucune erreur ORA- détectée dans les fichiers logs du mois ${CURRENT_DATE}.</pre>"
|
||||
else
|
||||
echo "<pre>$RESULT</pre>"
|
||||
fi
|
||||
|
||||
# afficher les dernières lignes des fichiers log pour voir les les exports se sont bien déroulés
|
||||
echo "<h3>Affichage des 10 premières et 10 dernières lignes des fichiers logs :</h3>"
|
||||
# préparation de la commande find : définition de la fonction d'affichage plus lisible
|
||||
show_log_excerpt() {
|
||||
local file="$1"
|
||||
echo "<br><b>--- ${file} ---</b> " # affiche le nom du fichier en gras
|
||||
echo "<pre>"
|
||||
head -10 "$file" # affiche les 10 première lignes dans le bloc PRE
|
||||
echo "</pre><pre>"
|
||||
tail -10 "$file" # affiche les 10 dernières lignes dans le bloc PRE
|
||||
echo "</pre>"
|
||||
}
|
||||
# export pour rendre la fonction accessible à bash -c
|
||||
export -f show_log_excerpt
|
||||
# afficher les dernières lignes des fichiers log pour voir les les exports se sont bien déroulés
|
||||
echo "<h3>Affichage des 10 premières et 10 dernières lignes des fichiers logs :</h3>"
|
||||
# préparation de la commande find : définition de la fonction d'affichage plus lisible
|
||||
show_log_excerpt() {
|
||||
local file="$1"
|
||||
echo "<br><b>--- ${file} ---</b> " # affiche le nom du fichier en gras
|
||||
echo "<pre>"
|
||||
head -10 "$file" # affiche les 10 première lignes dans le bloc PRE
|
||||
echo "</pre><pre>"
|
||||
tail -10 "$file" # affiche les 10 dernières lignes dans le bloc PRE
|
||||
echo "</pre>"
|
||||
}
|
||||
# export pour rendre la fonction accessible à bash -c
|
||||
export -f show_log_excerpt
|
||||
|
||||
# find appelle la fonction en lui passant $0 comme paramètre
|
||||
find "${EXPDP_DIR}" -iname "export_*.log" -exec bash -c 'show_log_excerpt "$0"' {} \;
|
||||
# find appelle la fonction en lui passant $0 comme paramètre
|
||||
find "${EXPDP_DIR}" -iname "export_*.log" -exec bash -c 'show_log_excerpt "$0"' {} \;
|
||||
fi
|
||||
44
sh/utils.sh
Normal file
44
sh/utils.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Fichier de fonctions utilitaires pour les scripts de rapport
|
||||
|
||||
# Fonction: log_info
|
||||
# Description: Affiche un message d'information dans les logs avec un timestamp.
|
||||
# Paramètres:
|
||||
# $1 - Le message à afficher.
|
||||
log_info() {
|
||||
echo "[INFO] $(date +'%Y-%m-%d %H:%M:%S') - ${1}"
|
||||
}
|
||||
|
||||
# Affiche un titre H2
|
||||
print_h2() {
|
||||
echo "<h2>$1</h2>"
|
||||
}
|
||||
|
||||
# Exécute une commande et affiche sa sortie dans une balise <pre>
|
||||
# Si la commande échoue, elle affiche un message d'erreur mis en évidence.
|
||||
run_and_print() {
|
||||
local cmd="$1"
|
||||
local cmd_html
|
||||
|
||||
# Échapper les caractères HTML pour un affichage sûr
|
||||
cmd_html=$(echo "${cmd}" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
|
||||
|
||||
echo "<br><pre>"
|
||||
# Affiche la commande échappée en rouge et gras
|
||||
echo "<b style=\"color:red;\">${cmd_html}</b>"
|
||||
|
||||
# Ajoute une ligne vide pour la séparation
|
||||
echo ""
|
||||
|
||||
# Exécute la commande originale, redirige stderr vers stdout pour tout capturer
|
||||
if output=$(eval "${cmd}" 2>&1); then
|
||||
echo "$output"
|
||||
else
|
||||
echo "<div class=\"error-block\">"
|
||||
echo "ERREUR: La commande a échoué avec le message suivant :"
|
||||
echo "$output"
|
||||
echo "</div>"
|
||||
fi
|
||||
echo "</pre>"
|
||||
}
|
||||
Reference in New Issue
Block a user