"MaJ version socle"
This commit is contained in:
115
lib/message.lib
115
lib/message.lib
@@ -2,8 +2,8 @@
|
||||
## Script : message.lib
|
||||
## Module Puppet : gnc-script_core_dtsi
|
||||
## Auteur : Emmanuel Confrere
|
||||
## Date : 29-06-2017
|
||||
## Version : 1.2.1
|
||||
## Date : 31-08-2017
|
||||
## Version : 1.3.5
|
||||
## Objet : Gestion des message sur la console et dans les divers fichiers de trace
|
||||
##
|
||||
## Fonction : fct_message
|
||||
@@ -37,28 +37,52 @@
|
||||
# 1.2.0 13-04-2017 - Emmanuel Confrere - Evo : Journalisation du compte d execution dans l historique
|
||||
# 1.2.1 29-06-2017 - Emmanuel Confrere - Ano : Fonctionnement inattendu sous Bash 3.2.25
|
||||
# la fonction logname ne renvoi rien ?
|
||||
# 1.2.2 20-11-2017 - Doug Le Tough - Evo : Modification du format de la date afin qu'il soit independant
|
||||
# de la locale utilisee.
|
||||
# 1.3.0 07-08-2017 - Emmanuel Confrere - Evo : Optimisation performance - Suppression des comparaisons de chaine.
|
||||
# Correction Anomalie de l option -debug si mode interactif
|
||||
# 1.3.1 10-08-2017 - Emmanuel Confrere - Ano : En mode interactif, l option debug ne limite pas l affichage
|
||||
# en fonction du niveau positionnee sur le shell et celui du
|
||||
# message !
|
||||
# Correction et optimisation du traitement.
|
||||
# 1.3.2 21/08/2017 - Emmanuel Confrere - Ano : En mode interactif affiche systematiquement les message debug
|
||||
# de niveau zero. Meme si SH_NIV_DEBUG n est pas initialise !
|
||||
# Correction pour que l affichage ne soit effectif que si
|
||||
# la variable SH_NIV_DEBUG est initialise dans le shell courant.
|
||||
# 1.3.3 31-08-2017 - Emmanuel Confrere - Ano : Dans le cas d un message contruit avec un tableau de cette facon ${A[@]}
|
||||
# la libraire considere qu il sagit de plusieur argument et
|
||||
# tronque le message.
|
||||
# Pour corriger nous concatenons les messages avec un espace separateur.
|
||||
# pour eviter la concatenation si cette derniere pose probleme
|
||||
# presenter le message avec une variable tampon :
|
||||
# B="${A[@]}"
|
||||
# fct_message "coucou ${B} ..."
|
||||
# 1.3.4 31-08-2017 - Emmanuel Confrere - Ano : Introduction d une anomalie !
|
||||
# Erreur de syntaxe
|
||||
# 1.3.5 31-08-2017 - Emmanuel Confrere - Ano : Introduction d une autre ano !
|
||||
# Format de sortie modifier (ajout systematique d un espace)
|
||||
##----------------------------------------------------------------------------
|
||||
|
||||
function fct_message
|
||||
{
|
||||
local L_TEXT="" # Texte a afficher
|
||||
local L_TIME_STAMP=`date "+%Y%m%d %H:%M:%S"` # Horrodatage a ajouter au texte
|
||||
local L_EXISTE_REP
|
||||
local L_NB_PARAM=0 # Nb de parametre de la ligne de commande
|
||||
local L_TEXT="" # Texte a afficher
|
||||
local L_TIME_STAMP=`date "+%x %X"` # Horrodatage a ajouter au texte
|
||||
local L_INTER=0 # Mode interactif 0->non, 1->oui
|
||||
local L_EXISTE_REP # Controle l existance des repertoire de socle 0->OK 1->NOK
|
||||
local L_NB_PARAM=0 # Nb de parametre de la ligne de commande
|
||||
local L_TMP
|
||||
local L_TMP2
|
||||
local L_OPT # Nom des option
|
||||
local L_OPTION_DBG="non" # Message de debug
|
||||
local L_OPTION_SID="" # Affichage du SH_SESSION_IDP a l ecran
|
||||
local L_NIV_DEBUG=0 # Niveau de trace par defaut 0=aucune
|
||||
local L_OPTION_CPT="non" # Message de compte rendu
|
||||
local L_OPTION_HIST="non" # Message pour l historique
|
||||
local L_COULEUR="" # Couleur du texte avec l option -color
|
||||
local L_OPTION_COULEUR="non"
|
||||
local L_OPT # Nom des option
|
||||
local L_OPTION_DBG=0 # Message de debug
|
||||
local L_OPTION_SID="" # Affichage du SH_SESSION_IDP a l ecran
|
||||
local L_NIV_DEBUG=0 # Niveau de trace par defaut 0=aucune
|
||||
local L_OPTION_CPT=0 # Message de compte rendu
|
||||
local L_OPTION_HIST=0 # Message pour l historique
|
||||
local L_COULEUR="" # Couleur du texte avec l option -color
|
||||
local L_OPTION_COULEUR=0
|
||||
local L_LIST_COULEUR="noir:0;30 rouge:0;31 vert:0;32 jaune:1;33 bleu:1;34 rose:0;35 cyan:0;36 gris:0;37 orange:0;33 blanc:1;37 "
|
||||
|
||||
# - Mode interactif ?
|
||||
[ -z "${SH_SESSION_ID}" ] && L_INTER=1
|
||||
|
||||
# - recuperation des parametres en entree
|
||||
L_TMP=1
|
||||
L_NB_PARAM=$#
|
||||
@@ -66,10 +90,10 @@ while [ ${L_TMP} -le ${L_NB_PARAM} ]
|
||||
do
|
||||
L_OPT="$1"
|
||||
case "${L_OPT}" in
|
||||
"-cpt") L_OPTION_CPT="oui" ;;
|
||||
"-nolog") L_OPTION_NOLOG="oui" ;;
|
||||
"-hist") L_OPTION_HIST="oui" ;;
|
||||
"-color") L_OPTION_COULEUR="oui"
|
||||
"-cpt") L_OPTION_CPT=1 ;;
|
||||
"-nolog") L_OPTION_NOLOG=1 ;;
|
||||
"-hist") L_OPTION_HIST=1 ;;
|
||||
"-color") L_OPTION_COULEUR=1
|
||||
L_ARG=`echo $2|tr A-Z a-z`
|
||||
L_TMP2=${L_ARG:0:1}
|
||||
if [ "${L_TMP2}" != "-" ]
|
||||
@@ -77,12 +101,12 @@ do
|
||||
# on recherche la correspondance numerique de la couleur
|
||||
L_COULEUR=`echo ${L_LIST_COULEUR}|sed "s/.*${L_ARG}:\([0-1];3[0-7]\) .*/\1/"`
|
||||
# Si on ne la trouve pas on annule la colorisation
|
||||
[ ${#L_COULEUR} -ne 4 ] && L_OPTION_COULEUR="non"
|
||||
[ ${#L_COULEUR} -ne 4 ] && L_OPTION_COULEUR=0
|
||||
L_TMP=$(( ${L_TMP} + 1 ))
|
||||
shift
|
||||
fi ;;
|
||||
|
||||
"-debug") L_OPTION_DBG="oui"
|
||||
"-debug") L_OPTION_DBG=1
|
||||
L_ARG="$2"
|
||||
L_TMP2=${L_ARG:0:1}
|
||||
if [ "${L_TMP2}" != "-" ]
|
||||
@@ -100,56 +124,49 @@ do
|
||||
else
|
||||
L_NIV_DEBUG=1
|
||||
fi
|
||||
[ ${L_NIV_DEBUG} -gt ${SH_NIV_DEBUG} ] && return 0 ;;
|
||||
*) L_TEXT="${L_OPT}" ;;
|
||||
[ ${L_NIV_DEBUG} -gt 0${SH_NIV_DEBUG} -o -z "${SH_NIV_DEBUG}" ] && return 0 ;;
|
||||
*) [ -z "${L_TEXT}" ] && L_TEXT="${L_OPT}" || L_TEXT="${L_TEXT} ${L_OPT}" ;;
|
||||
esac
|
||||
L_TMP=$(( ${L_TMP} + 1 ))
|
||||
shift
|
||||
done
|
||||
|
||||
# - controle que la fonction est lance depuis un shell
|
||||
if [ -z "${SH_SESSION_ID}" ]
|
||||
# - Controle du mode d execution ...
|
||||
if (( ${L_INTER} ))
|
||||
then
|
||||
# -- La fonction est executer en mode inetractif (Pas dans un shell)
|
||||
# -- on autorise alors que l affichage sur la sortie standard
|
||||
SH_AFF_SID="non"
|
||||
SH_SILENCE="non"
|
||||
SH_NIV_DEBUG=0
|
||||
L_EXISTE_REP=1
|
||||
# -- La fonction est executer en mode interactif (Pas dans un script du socle)
|
||||
# -- on autorise alors uniquement l affichage sur la sortie standard
|
||||
L_EXISTE_REP=0
|
||||
else
|
||||
# - Mode shell...
|
||||
# - On control l'existance des repertoires
|
||||
[ -d ${NC_EXPL_HST} -a -d ${NC_EXPL_LOG} -a -d ${NC_EXPL_CPT} ] && L_EXISTE_REP=0 || L_EXISTE_REP=1
|
||||
[ -d ${NC_EXPL_HST} -a -d ${NC_EXPL_LOG} -a -d ${NC_EXPL_CPT} ] && L_EXISTE_REP=1 || L_EXISTE_REP=0
|
||||
fi
|
||||
|
||||
# - initialisation des variables
|
||||
[ "${SH_AFF_SID}" = "oui" ] && L_OPTION_SID="[${SH_SESSION_IDP}] "
|
||||
L_OPTION_NOLOG=${L_OPTION_NOLOG:="non"}
|
||||
L_OPTION_NOLOG=${L_OPTION_NOLOG:=0}
|
||||
|
||||
# - Ecriture des messages
|
||||
# - Ajout d une indentation si elle est definie
|
||||
[ -n "${SH_INDENT_MSG}" ] && L_TEXT="${SH_INDENT_MSG} ${L_TEXT}"
|
||||
if [ "${L_OPTION_DBG}" = "oui" ]
|
||||
if (( ${L_OPTION_DBG} ))
|
||||
then
|
||||
[ ${L_EXISTE_REP} -eq 0 ] && echo "${L_TIME_STAMP} [${SH_SESSION_IDP}] : <Debug_${L_NIV_DEBUG}> ${L_TEXT}" >> ${SH_FICLOG}
|
||||
(( ${L_EXISTE_REP} & ! ${L_INTER} )) && echo "${L_TIME_STAMP} [${SH_SESSION_IDP}] : <Debug_${L_NIV_DEBUG}> ${L_TEXT}" >> ${SH_FICLOG}
|
||||
(( ${L_INTER} )) && echo "<Debug_${L_NIV_DEBUG}> ${L_TEXT}"
|
||||
else
|
||||
[ ${L_EXISTE_REP} -eq 0 -a "${L_OPTION_CPT}" = "oui" -a "${L_OPTION_HIST}" = "non" ] && echo "${L_TIME_STAMP} : ${L_TEXT}" >> ${SH_FICCPT}
|
||||
[ ${L_EXISTE_REP} -eq 0 -a "${L_OPTION_CPT}" = "non" -a "${L_OPTION_HIST}" = "oui" ] && echo "${L_TIME_STAMP} : ${SH_LOGUSER} : ${SH_EXECUSER} : ${L_TEXT}" >> ${SH_FICTRC}
|
||||
if [ "${L_OPTION_NOLOG}" = "non" ]
|
||||
(( ${L_EXISTE_REP} & ${L_OPTION_CPT} & ! ${L_OPTION_HIST} )) && echo "${L_TIME_STAMP} : ${L_TEXT}" >> ${SH_FICCPT}
|
||||
(( ${L_EXISTE_REP} & ! ${L_OPTION_CPT} & ${L_OPTION_HIST} )) && echo "${L_TIME_STAMP} : ${SH_LOGUSER} : ${SH_EXECUSER} : ${L_TEXT}" >> ${SH_FICTRC}
|
||||
if (( ! ${L_OPTION_NOLOG} ))
|
||||
then
|
||||
[ ${L_EXISTE_REP} -eq 0 -a "${L_OPTION_CPT}" = "non" -a "${L_OPTION_HIST}" = "non" ] && echo "${L_TIME_STAMP} [${SH_SESSION_IDP}] : ${L_TEXT}" >> ${SH_FICLOG}
|
||||
[ ${L_EXISTE_REP} -eq 0 -a "${L_OPTION_CPT}" = "oui" -a "${L_OPTION_HIST}" = "oui" ] && echo "${L_TIME_STAMP} : ${L_TEXT}" >> ${SH_FICLOG}
|
||||
(( ! ${L_INTER} & ${L_EXISTE_REP} & ! ${L_OPTION_CPT} & ! ${L_OPTION_HIST} )) && echo "${L_TIME_STAMP} [${SH_SESSION_IDP}] : ${L_TEXT}" >> ${SH_FICLOG}
|
||||
(( ! ${L_INTER} & ${L_EXISTE_REP} & ${L_OPTION_CPT} & ${L_OPTION_HIST} )) && echo "${L_TIME_STAMP} : <lib:fct_message> : Option -cpt et -hist ! - ${L_TEXT}" >> ${SH_FICLOG}
|
||||
fi
|
||||
if [ "${SH_SILENCE}" = "non" -a "${L_OPTION_HIST}" = "non" ]
|
||||
if [ \( "${SH_SILENCE}" = "non" -a "${L_OPTION_HIST}" = 0 \) -o ${L_INTER} -eq 1 ]
|
||||
then
|
||||
if [ "${L_OPTION_COULEUR}" = "oui" ]
|
||||
then
|
||||
echo -e "${L_OPTION_SID}\033[${L_COULEUR}m${L_TEXT}\033[0m"
|
||||
else
|
||||
echo -e "${L_OPTION_SID}${L_TEXT}"
|
||||
fi
|
||||
(( ${L_OPTION_COULEUR} )) && echo -e "${L_OPTION_SID}\033[${L_COULEUR}m${L_TEXT}\033[0m" || echo -e "${L_OPTION_SID}${L_TEXT}"
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
typeset -Ffx fct_message
|
||||
typeset -Ffx fct_message
|
||||
Reference in New Issue
Block a user