[1709] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # |
---|
| 4 | # Fonctions utiles pour les scripts de Pack IPSL |
---|
| 5 | # |
---|
| 6 | |
---|
| 7 | function DEM_read_state { |
---|
| 8 | # Lire l'état du pack pour une simulation |
---|
| 9 | local L_CONFIG_FILE=${1} |
---|
| 10 | local L_CONFIG_CARD=${2} |
---|
| 11 | |
---|
| 12 | local L_OLD_STATE=$( grep ${L_CONFIG_CARD} ${L_CONFIG_FILE} | awk '{print $2}' ) |
---|
| 13 | |
---|
| 14 | if [ ${?} -eq 0 ] |
---|
| 15 | then |
---|
| 16 | echo ${L_OLD_STATE} |
---|
| 17 | return 0 |
---|
| 18 | else |
---|
| 19 | return 1 |
---|
| 20 | fi |
---|
| 21 | return 0 |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | function DEM_write_state { |
---|
| 25 | # Mettre à jour l'état du pack pour une simulation |
---|
| 26 | local L_CONFIG_FILE=${1} |
---|
| 27 | local L_CONFIG_CARD=${2} |
---|
| 28 | local L_NEW_STATE=${3} |
---|
[1729] | 29 | |
---|
| 30 | local L_MAX_TRY=10 L_TRY=0 L_CHECK L_PP |
---|
| 31 | |
---|
| 32 | # On essaye ${L_MAX_TRY} fois de mettre à jour le fichier |
---|
| 33 | while [ ${L_TRY} -le ${L_MAX_TRY} ] |
---|
| 34 | do |
---|
| 35 | if [[ ! -f ${L_CONFIG_FILE}.lock ]] |
---|
| 36 | then |
---|
| 37 | echo ${$} >> ${L_CONFIG_FILE}.lock ; chmod -w ${L_CONFIG_FILE}.lock |
---|
| 38 | L_CHECK=$( wc -l ${L_CONFIG_FILE}.lock | awk '{print $1}' ) |
---|
| 39 | if [[ ${L_CHECK} -gt 1 ]] |
---|
| 40 | then |
---|
| 41 | DEM_log -0 "Erreur. Plusieurs processus on pose un verrou sur ${L_CONFIG_FILE}" |
---|
| 42 | for L_PP in $( awk '{print $1}' ${L_CONFIG_FILE}.lock ) |
---|
| 43 | do |
---|
| 44 | DEM_log -0 "Erreur. Process : ${L_PP}" |
---|
| 45 | done |
---|
| 46 | return 1 |
---|
| 47 | fi |
---|
| 48 | |
---|
| 49 | local L_OLD_LINE=$( grep ${L_CONFIG_CARD} ${L_CONFIG_FILE} ) |
---|
| 50 | [[ ${?} -eq 0 ]] || ( return 1 ; ) |
---|
| 51 | if [[ ${L_OLD_LINE} = "" ]] |
---|
| 52 | then |
---|
| 53 | DEM_log -0 "Erreur. Dans le fichier : ${L_CONFIG_FILE}, Experience ${L_CONFIG_CARD} non trouvee" |
---|
| 54 | return 1 |
---|
| 55 | fi |
---|
| 56 | local L_OLD_STATE=$( echo ${L_OLD_LINE} | awk '{print $2}' ) |
---|
| 57 | [[ ${?} -eq 0 ]] || ( return 1 ; ) |
---|
| 58 | |
---|
| 59 | L_NEW_LINE="${L_CONFIG_CARD} ${L_NEW_STATE}" |
---|
| 60 | |
---|
| 61 | sed -i "s%${L_OLD_LINE}%${L_NEW_LINE}%" ${L_CONFIG_FILE} |
---|
| 62 | rm -f ${L_CONFIG_FILE}.lock |
---|
| 63 | break |
---|
| 64 | else |
---|
| 65 | (( L_TRY = L_TRY + 1 )) |
---|
| 66 | DEM_log -3 "Fichier ${L_CONFIG_FILE} en cours de modif par un autre processus. Essai ${L_TRY}" |
---|
| 67 | sleep 1 |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | done |
---|
[1709] | 71 | |
---|
[1729] | 72 | if [[ ${L_TRY} -ge ${L_MAX_TRY} ]] |
---|
[1709] | 73 | then |
---|
| 74 | DEM_log -0 "Erreur. Verrou sur le fichier : ${L_CONFIG_FILE}" |
---|
| 75 | return 1 |
---|
| 76 | fi |
---|
[1729] | 77 | |
---|
[1709] | 78 | return 0 |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | function DEM_min { |
---|
| 82 | # Calcul du minimum d'un nombre quelconque d'entiers |
---|
| 83 | local l_min=${1} l_xx |
---|
| 84 | |
---|
| 85 | for l_xx in ${*:2:${#}} |
---|
| 86 | do |
---|
| 87 | [[ ${l_xx} -lt ${l_min} ]] && l_min=${l_xx} |
---|
| 88 | done |
---|
| 89 | echo ${l_min} |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | function DEM_max { |
---|
| 93 | # Calcul du maximum d'un nombre quelconque d'entiers |
---|
| 94 | local l_max=${1} l_xx |
---|
| 95 | |
---|
| 96 | for l_xx in ${*:2:${#}} |
---|
| 97 | do |
---|
| 98 | [[ ${l_xx} -gt ${l_max} ]] && l_max=${l_xx} |
---|
| 99 | done |
---|
| 100 | echo ${l_max} |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function DEM_log { |
---|
| 104 | # Affichage d'un message sur stdout et dans un fichier de log |
---|
| 105 | # DEM_log [-0|-1|-2|-3] Message |
---|
| 106 | # |
---|
[1729] | 107 | local MESSAGE P_LINE L_NAME |
---|
[1709] | 108 | LOG_LEV=${LOG_LEV:-3} |
---|
| 109 | local OPTARG OPTIND L_LOG=1 |
---|
[1900] | 110 | local L_DEM_LOG=${DEM_LOG:-${TMP_MIGR_DATA}/dem_log.${$}} |
---|
[1709] | 111 | |
---|
[1729] | 112 | while getopts 0123 L_NAME |
---|
[1709] | 113 | do |
---|
[1729] | 114 | case ${L_NAME} in |
---|
[1709] | 115 | ( 0 ) L_LOG=1 ;; |
---|
| 116 | ( 1 ) L_LOG=1 ;; |
---|
| 117 | ( 2 ) L_LOG=2 ;; |
---|
| 118 | ( 3 ) L_LOG=3 ;; |
---|
| 119 | esac |
---|
| 120 | done |
---|
| 121 | shift $(( ${OPTIND} - 1 )) |
---|
| 122 | |
---|
| 123 | if [[ ${L_LOG} -le ${LOG_LEV} ]] |
---|
| 124 | then |
---|
| 125 | MESSAGE=${*} |
---|
| 126 | P_LINE="$(date) - ${MESSAGE}" |
---|
| 127 | |
---|
| 128 | echo ${P_LINE} |
---|
| 129 | echo ${P_LINE} >> ${L_DEM_LOG} |
---|
| 130 | fi |
---|
| 131 | return |
---|
| 132 | } |
---|
[1729] | 133 | |
---|
[1822] | 134 | # gpdebug : fonctions de gestion des erreurs ######################################################## |
---|
| 135 | function DEM_errorSend { |
---|
| 136 | # Envoi d'un msg d'erreur au programme principal. |
---|
| 137 | # Suppression des processus du programme principal au fils emetteur de l'erreur |
---|
| 138 | |
---|
| 139 | echo "########## DEM_errorSend : Error detected ==> Sending an error..." |
---|
| 140 | |
---|
| 141 | msgToSend=${1} |
---|
| 142 | listPIDtoKill=${2} |
---|
| 143 | if [ "x${listPIDtoKill}" == "x" ] |
---|
| 144 | then |
---|
| 145 | listPIDtoKill=${listPID} |
---|
| 146 | fi |
---|
| 147 | # -------------------------------- |
---|
| 148 | # Verif du format de listPIDtoKill |
---|
| 149 | # -------------------------------- |
---|
| 150 | listPIDformat='^[[:digit:]]*\([[:blank:]][[:digit:]]*\)*$' |
---|
| 151 | isListPIDformatOK=`echo ${listPIDtoKill} | grep -e ${listPIDformat} | wc -l ` |
---|
| 152 | if [ "x$isListPIDformatOK" == "x0" ] |
---|
| 153 | then |
---|
| 154 | echo " Attention : le format de la liste de PID est incorrecte :" |
---|
| 155 | echo " $listPIDtoKill" |
---|
| 156 | kill -TERM ${listPID} |
---|
| 157 | fi |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | # ----------------------------------- |
---|
| 161 | # Verif du Format du ${msgToSend} |
---|
| 162 | # ----------------------------------- |
---|
| 163 | errorFormat='^[^:]*\.sh:[[:digit:]]*:.*$' |
---|
| 164 | isErrorFormatOK=`echo ${msgToSend} | grep -e ${errorFormat} | wc -l ` |
---|
| 165 | if [ "x$isErrorFormatOK" == "x0" ] |
---|
| 166 | then |
---|
| 167 | echo " Attention : le format du message d'erreur est incorrect :" |
---|
| 168 | echo " $msgToSend" |
---|
| 169 | fi |
---|
| 170 | |
---|
| 171 | # Envoi du msg dans le fichier d'erreur |
---|
| 172 | # ------------------------------------- |
---|
| 173 | # test sur la var contenant le nom du fichier d'erreur |
---|
[1900] | 174 | if [ "x${errorMsgFile}" != "x${TMP_MIGR_DATA}/errorMsg.txt" ] |
---|
[1822] | 175 | then |
---|
| 176 | echo " Le fichier d'erreur a un nom incorrect" |
---|
| 177 | fi |
---|
| 178 | |
---|
| 179 | echo $msgToSend > $errorMsgFile |
---|
| 180 | |
---|
| 181 | echo "killing ${listPIDtoKill}" |
---|
| 182 | kill -TERM ${listPIDtoKill} |
---|
| 183 | |
---|
| 184 | exit -1 # utile : sinon le script qui appelle cette fonction continue un peu l'exec --> pas propre |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | function DEM_errorReceive { |
---|
| 188 | # Récupération et affichage du msg d'erreur emis par un processus fils |
---|
| 189 | |
---|
| 190 | # Lecture du msg dans le fichier d'erreur |
---|
| 191 | # --------------------------------------- |
---|
| 192 | # test sur la var contenant le nom du fichier d'erreur |
---|
[1900] | 193 | if [ "x${errorMsgFile}" != "x${TMP_MIGR_DATA}/errorMsg.txt" ] |
---|
[1822] | 194 | then |
---|
| 195 | echo " Le fichier d'erreur a un nom incorrect" |
---|
| 196 | exit -1 |
---|
| 197 | fi |
---|
| 198 | |
---|
| 199 | # Lecture |
---|
| 200 | errorReceived=`cat $errorMsgFile ` |
---|
| 201 | |
---|
| 202 | # ----------------------------------- |
---|
| 203 | # Verif du Format du ${errorReceived} |
---|
| 204 | # ----------------------------------- |
---|
| 205 | errorFormat='^[^:]*\.sh:[[:digit:]]*:.*$' |
---|
| 206 | isErrorFormatOK=`echo ${errorReceived} | grep -e ${errorFormat} | wc -l ` |
---|
| 207 | if [ "x$isErrorFormatOK" == "x0" ] |
---|
| 208 | then |
---|
| 209 | echo " Attention : le format du message d'erreur est incorrect :" |
---|
| 210 | echo " $errorReceived" |
---|
| 211 | exit -1 |
---|
| 212 | fi |
---|
| 213 | |
---|
| 214 | echo "########## DEM_errorReceive : $SCRIPT_NAME received an error..." |
---|
| 215 | echo $errorReceived |
---|
| 216 | |
---|
| 217 | # echo "Current PID:$$" |
---|
| 218 | # echo "FatherPID:$FatherPID" |
---|
| 219 | # On fait un bilan de la progression seulement si c'est une erreur bloquante : lorsque le proc pere est tue. |
---|
[1887] | 220 | # if [ "x${FatherPID}" == "x$$" ] |
---|
| 221 | # then |
---|
| 222 | # ./showListsProgress.sh $FileParam |
---|
| 223 | # fi |
---|
[1822] | 224 | |
---|
| 225 | exit -1 |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | # Verification de la version de nco chargee |
---|
| 229 | function check_nco_version |
---|
| 230 | { |
---|
| 231 | # nom du présent prog (pour gestion des erreurs) |
---|
| 232 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 233 | . /etc/profile |
---|
| 234 | module list >& myModuleList.txt |
---|
| 235 | |
---|
| 236 | if [ "x$?" != "x0" ] |
---|
| 237 | then |
---|
| 238 | # echo "La commande module list a rencontre un pb !" |
---|
| 239 | DEM_errorSend "${PROGNAME}:${LINENO}:La commande module list a rencontre un pb !" |
---|
| 240 | fi |
---|
| 241 | |
---|
| 242 | if [ ! -e myModuleList.txt ] |
---|
| 243 | then |
---|
| 244 | # echo "Le fichier 'myModuleList.txt' n existe pas" |
---|
| 245 | DEM_errorSend "${PROGNAME}:${LINENO}:Le fichier 'myModuleList.txt' n'existe pas." |
---|
| 246 | fi |
---|
| 247 | |
---|
| 248 | # Presence de la chaine "n) nco/" ou n est un nombre |
---|
| 249 | ncoLines=` grep -e '[[:digit:]]*) nco/' myModuleList.txt ` |
---|
| 250 | # ncoLines=` grep -e '[[:digit:]]*) nco/' moduleList.txt ` |
---|
| 251 | # echo "ncoLines=${ncoLines}|" |
---|
| 252 | # echo "----------------------------------------" |
---|
| 253 | |
---|
| 254 | # Plus besoin du myModuleList.txt |
---|
| 255 | rm -f myModuleList.txt |
---|
| 256 | |
---|
| 257 | # La chaine "nco" est remplacee par le caractere "#" |
---|
| 258 | temp1=`echo $ncoLines | sed 's;nco;#;g' ` |
---|
| 259 | # echo "$temp1" |
---|
| 260 | # echo "----------------------------------------" |
---|
| 261 | |
---|
| 262 | # On supprime tout ce qui n'est pas "n) #/..." avec n un nombre et "..." une chaine sans blanc |
---|
| 263 | temp2=`echo $temp1 | sed 's;[[:blank:]]*[[:digit:]]*) [^#][^[:blank:]]*;;g' ` |
---|
| 264 | # echo "$temp2" |
---|
| 265 | # echo "----------------------------------------" |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | # Recuperation du numero de version du nco au format x.y.z |
---|
| 269 | # C'est une liste de num de version (a priori ici, il pourrait y en avoir plusieurs, |
---|
| 270 | # mais dans les faits, les nco s'excluent les uns les autres) |
---|
| 271 | temp3=`echo $temp2 | sed 's;[[:blank:]]*[[:digit:]]*) #/;|;g' ` |
---|
| 272 | temp3=`echo $temp3 | sed 's;^|;;g' ` |
---|
| 273 | temp3=`echo $temp3 | sed 's;|; ;g' ` |
---|
| 274 | # echo "$temp3" |
---|
| 275 | # echo "----------------------------------------" |
---|
| 276 | |
---|
| 277 | # comptage du nombre de nco |
---|
| 278 | versionNCO= |
---|
| 279 | count=0 |
---|
| 280 | for ver in $temp3 |
---|
| 281 | do |
---|
| 282 | # echo "ver=$ver" |
---|
| 283 | versionNCO=$ver |
---|
| 284 | count=$(( $count + 1 )) |
---|
| 285 | done |
---|
| 286 | # echo "count=$count" |
---|
| 287 | |
---|
| 288 | # si aucun nco n'est charge, on sort. |
---|
| 289 | if [ $count -eq 0 ] |
---|
| 290 | then |
---|
| 291 | # echo "nco pas charge" |
---|
| 292 | DEM_errorSend "${PROGNAME}:${LINENO}:Aucun nco n'est charge" |
---|
| 293 | fi |
---|
| 294 | |
---|
| 295 | # si plus d'un nco sont charges, on sort (n'arrive jamais en pratique). |
---|
| 296 | if [ $count -gt 1 ] |
---|
| 297 | then |
---|
| 298 | DEM_errorSend "${PROGNAME}:${LINENO}:Au moins 2 versions de nco sont chargees" |
---|
| 299 | fi |
---|
| 300 | |
---|
| 301 | # Si un seul nco est charge, on supprime les "." de son numero de version (x.y.z ==> xyz) |
---|
| 302 | verNCOnumber=`echo $versionNCO | sed 's;[^[:digit:]];;g' ` |
---|
| 303 | # echo "versionNCO=$versionNCO" |
---|
| 304 | |
---|
| 305 | # On verifie que xyz est un nombre a 3 chiffres |
---|
[1838] | 306 | verNCOnumberOK=`echo $verNCOnumber | grep -e '^[0-9]\{3\}$' | wc -l ` |
---|
[1849] | 307 | # if ! [[ "$verNCOnumber" =~ ^[0-9]\{3\}$ ]] # gpdebug : ne marche pas sous curie si ksh. |
---|
[1838] | 308 | if [ "x${verNCOnumberOK}" == "x0" ] |
---|
[1822] | 309 | then |
---|
| 310 | # echo "verNCOnumber is not a number" |
---|
| 311 | DEM_errorSend "${PROGNAME}:${LINENO}:La variable verNCOnumber n'est pas un nombre --> $verNCOnumber" |
---|
| 312 | fi |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | # On verifie que le num de version est >= 4.1.0 |
---|
| 316 | if [ $verNCOnumber -lt 410 ] |
---|
| 317 | then |
---|
| 318 | # echo "version < 4.1.0 . STOP." |
---|
| 319 | DEM_errorSend "${PROGNAME}:${LINENO}:La version de nco < 4.1.0 ==> $versionNCO" |
---|
| 320 | fi |
---|
| 321 | |
---|
| 322 | echo "La version de nco chargee est : $versionNCO" |
---|
| 323 | |
---|
| 324 | } |
---|
| 325 | |
---|
[1875] | 326 | |
---|
| 327 | # Verification de la version de nco chargee sur ulam (machine IDRIS) |
---|
| 328 | function check_nco_version_idris |
---|
| 329 | { |
---|
| 330 | # nom du présent prog (pour gestion des erreurs) |
---|
| 331 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 332 | . /etc/profile |
---|
| 333 | module list >& myModuleList.txt |
---|
| 334 | |
---|
| 335 | if [ "x$?" != "x0" ] |
---|
| 336 | then |
---|
| 337 | # echo "La commande module list a rencontre un pb !" |
---|
| 338 | DEM_errorSend "${PROGNAME}:${LINENO}:La commande module list a rencontre un pb !" |
---|
| 339 | fi |
---|
| 340 | |
---|
| 341 | if [ ! -e myModuleList.txt ] |
---|
| 342 | then |
---|
| 343 | # echo "Le fichier 'myModuleList.txt' n existe pas" |
---|
| 344 | DEM_errorSend "${PROGNAME}:${LINENO}:Le fichier 'myModuleList.txt' n'existe pas." |
---|
| 345 | fi |
---|
| 346 | |
---|
| 347 | # Presence de la chaine "n) nco/" ou n est un nombre |
---|
| 348 | ncoLines=` grep -e '[[:digit:]]*) nco/' myModuleList.txt ` |
---|
| 349 | # ncoLines=` grep -e '[[:digit:]]*) nco/' moduleList.txt ` |
---|
| 350 | # echo "ncoLines=${ncoLines}|" |
---|
| 351 | # echo "----------------------------------------" |
---|
| 352 | |
---|
| 353 | # Plus besoin du myModuleList.txt |
---|
| 354 | rm -f myModuleList.txt |
---|
| 355 | |
---|
| 356 | # La chaine "nco" est remplacee par le caractere "#" |
---|
| 357 | temp1=`echo $ncoLines | sed 's;nco;#;g' ` |
---|
| 358 | # echo "$temp1" |
---|
| 359 | # echo "----------------------------------------" |
---|
| 360 | |
---|
| 361 | # On supprime tout ce qui n'est pas "n) #/..." avec n un nombre et "..." une chaine sans blanc |
---|
| 362 | temp2=`echo $temp1 | sed 's;[[:blank:]]*[[:digit:]]*) [^#][^[:blank:]]*;;g' ` |
---|
| 363 | # echo "$temp2" |
---|
| 364 | # echo "----------------------------------------" |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | # Recuperation du numero de version du nco au format x.y.z |
---|
| 368 | # C'est une liste de num de version (a priori ici, il pourrait y en avoir plusieurs, |
---|
| 369 | # mais dans les faits, les nco s'excluent les uns les autres) |
---|
| 370 | temp3=`echo $temp2 | sed 's;[[:blank:]]*[[:digit:]]*) #/;|;g' ` |
---|
| 371 | temp3=`echo $temp3 | sed 's;^|;;g' ` |
---|
| 372 | temp3=`echo $temp3 | sed 's;|; ;g' ` |
---|
| 373 | # echo "$temp3" |
---|
| 374 | # echo "----------------------------------------" |
---|
| 375 | |
---|
| 376 | # comptage du nombre de nco |
---|
| 377 | versionNCO= |
---|
| 378 | count=0 |
---|
| 379 | for ver in $temp3 |
---|
| 380 | do |
---|
| 381 | # echo "ver=$ver" |
---|
| 382 | versionNCO=$ver |
---|
| 383 | count=$(( $count + 1 )) |
---|
| 384 | done |
---|
| 385 | # echo "count=$count" |
---|
| 386 | |
---|
| 387 | # si aucun nco n'est charge, on sort. |
---|
| 388 | if [ $count -eq 0 ] |
---|
| 389 | then |
---|
| 390 | # echo "nco pas charge" |
---|
| 391 | DEM_errorSend "${PROGNAME}:${LINENO}:Aucun nco n'est charge" |
---|
| 392 | fi |
---|
| 393 | |
---|
| 394 | # si plus d'un nco sont charges, on sort (n'arrive jamais en pratique). |
---|
| 395 | if [ $count -gt 1 ] |
---|
| 396 | then |
---|
| 397 | DEM_errorSend "${PROGNAME}:${LINENO}:Au moins 2 versions de nco sont chargees" |
---|
| 398 | fi |
---|
| 399 | |
---|
| 400 | # Si un seul nco est charge, on supprime les "." de son numero de version (x.y.z ==> xyz) |
---|
| 401 | verNCOnumber=`echo $versionNCO | sed 's;[^[:digit:]];;g' ` |
---|
| 402 | # echo "versionNCO=$versionNCO" |
---|
| 403 | |
---|
| 404 | # On verifie que xyz est un nombre a 3 chiffres |
---|
| 405 | verNCOnumberOK=`echo $verNCOnumber | grep -e '^[0-9]\{3\}$' | wc -l ` |
---|
| 406 | # if ! [[ "$verNCOnumber" =~ ^[0-9]\{3\}$ ]] # gpdebug : ne marche pas sous curie si ksh. |
---|
| 407 | if [ "x${verNCOnumberOK}" == "x0" ] |
---|
| 408 | then |
---|
| 409 | # echo "verNCOnumber is not a number" |
---|
| 410 | DEM_errorSend "${PROGNAME}:${LINENO}:La variable verNCOnumber n'est pas un nombre --> $verNCOnumber" |
---|
| 411 | fi |
---|
| 412 | |
---|
| 413 | # On verifie que le num de version est >= 4.0.5 |
---|
| 414 | if [ $verNCOnumber -lt 405 ] |
---|
| 415 | then |
---|
| 416 | # echo "version < 4.0.5 . STOP." |
---|
| 417 | DEM_errorSend "${PROGNAME}:${LINENO}:La version de nco < 4.0.5 ==> $versionNCO" |
---|
| 418 | fi |
---|
| 419 | |
---|
| 420 | echo "La version de nco chargee est : $versionNCO" |
---|
| 421 | |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | function check_netcdf_idris |
---|
| 425 | { |
---|
| 426 | # nom du présent prog (pour gestion des erreurs) |
---|
| 427 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 428 | . /etc/profile |
---|
| 429 | module list >& myModuleList.txt |
---|
| 430 | |
---|
| 431 | if [ "x$?" != "x0" ] |
---|
| 432 | then |
---|
| 433 | # echo "La commande module list a rencontre un pb !" |
---|
| 434 | DEM_errorSend "${PROGNAME}:${LINENO}:La commande module list a rencontre un pb !" |
---|
| 435 | fi |
---|
| 436 | |
---|
| 437 | if [ ! -e myModuleList.txt ] |
---|
| 438 | then |
---|
| 439 | # echo "Le fichier 'myModuleList.txt' n existe pas" |
---|
| 440 | DEM_errorSend "${PROGNAME}:${LINENO}:Le fichier 'myModuleList.txt' n'existe pas." |
---|
| 441 | fi |
---|
| 442 | |
---|
| 443 | # Presence de la chaine "n) nco/" ou n est un nombre |
---|
| 444 | nb_of_libLines=` grep -e '[[:digit:]]*) netcdf/' myModuleList.txt | wc -l ` |
---|
| 445 | |
---|
| 446 | if [ "x${nb_of_libLines}" == "x0" ] |
---|
| 447 | then |
---|
| 448 | DEM_errorSend "${PROGNAME}:${LINENO}:Aucun netCDF n'est charge" |
---|
| 449 | fi |
---|
| 450 | |
---|
| 451 | # Plus besoin du myModuleList.txt |
---|
| 452 | rm -f myModuleList.txt |
---|
| 453 | } |
---|
| 454 | |
---|
[1853] | 455 | function check_libccc_user |
---|
| 456 | { |
---|
| 457 | # nom du présent prog (pour gestion des erreurs) |
---|
| 458 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 459 | . /etc/profile |
---|
| 460 | module list >& myModuleList.txt |
---|
| 461 | |
---|
| 462 | if [ "x$?" != "x0" ] |
---|
| 463 | then |
---|
| 464 | # echo "La commande module list a rencontre un pb !" |
---|
| 465 | DEM_errorSend "${PROGNAME}:${LINENO}:La commande module list a rencontre un pb !" |
---|
| 466 | fi |
---|
| 467 | |
---|
| 468 | if [ ! -e myModuleList.txt ] |
---|
| 469 | then |
---|
| 470 | # echo "Le fichier 'myModuleList.txt' n existe pas" |
---|
| 471 | DEM_errorSend "${PROGNAME}:${LINENO}:Le fichier 'myModuleList.txt' n'existe pas." |
---|
| 472 | fi |
---|
| 473 | |
---|
| 474 | # Presence de la chaine "n) nco/" ou n est un nombre |
---|
[1857] | 475 | nb_of_libLines=` grep -e '[[:digit:]]*) libccc_user/' myModuleList.txt | wc -l ` |
---|
| 476 | |
---|
[1853] | 477 | if [ "x${nb_of_libLines}" == "x0" ] |
---|
| 478 | then |
---|
| 479 | DEM_errorSend "${PROGNAME}:${LINENO}:Aucun libccc_user n'est charge" |
---|
| 480 | fi |
---|
| 481 | |
---|
| 482 | # Plus besoin du myModuleList.txt |
---|
[1864] | 483 | rm -f myModuleList.txt |
---|
[1853] | 484 | |
---|
| 485 | } |
---|
[1864] | 486 | |
---|
| 487 | |
---|
| 488 | function check_cdo |
---|
| 489 | { |
---|
| 490 | # nom du présent prog (pour gestion des erreurs) |
---|
| 491 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 492 | . /etc/profile |
---|
| 493 | module list >& myModuleList.txt |
---|
| 494 | |
---|
| 495 | if [ "x$?" != "x0" ] |
---|
| 496 | then |
---|
| 497 | # echo "La commande module list a rencontre un pb !" |
---|
| 498 | DEM_errorSend "${PROGNAME}:${LINENO}:La commande module list a rencontre un pb !" |
---|
| 499 | fi |
---|
| 500 | |
---|
| 501 | if [ ! -e myModuleList.txt ] |
---|
| 502 | then |
---|
| 503 | # echo "Le fichier 'myModuleList.txt' n existe pas" |
---|
| 504 | DEM_errorSend "${PROGNAME}:${LINENO}:Le fichier 'myModuleList.txt' n'existe pas." |
---|
| 505 | fi |
---|
| 506 | |
---|
| 507 | # Presence de la chaine "n) nco/" ou n est un nombre |
---|
| 508 | nb_of_libLines=` grep -e '[[:digit:]]*) cdo/' myModuleList.txt | wc -l ` |
---|
| 509 | |
---|
| 510 | if [ "x${nb_of_libLines}" == "x0" ] |
---|
| 511 | then |
---|
| 512 | DEM_errorSend "${PROGNAME}:${LINENO}:Aucun cdo n'est charge" |
---|
| 513 | fi |
---|
| 514 | |
---|
| 515 | # Plus besoin du myModuleList.txt |
---|
| 516 | rm -f myModuleList.txt |
---|
| 517 | |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | |
---|
[1822] | 521 | function prepareMonitoringDir |
---|
| 522 | { |
---|
| 523 | # nom du présent prog (pour gestion des erreurs) |
---|
| 524 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 525 | |
---|
| 526 | MonitoringDirDefined=`echo $MonitoringDir | grep "SuiviListes" | wc -l ` |
---|
| 527 | if [ "x${workFlowDirDefined}" == "x0" ] |
---|
| 528 | then |
---|
| 529 | DEM_errorSend "${PROGNAME}:${LINENO}:Le repertoire de suivi est mal defini." |
---|
| 530 | fi |
---|
| 531 | |
---|
| 532 | # Si l'option de forcage de toute les etapes est activee, |
---|
| 533 | # on vide le fichier |
---|
| 534 | if [ "x${execEveryStep}" == "x1" ] |
---|
| 535 | then |
---|
| 536 | echo "${MonitoringDir}:destruction..." |
---|
| 537 | rm -rf ${MonitoringDir} |
---|
| 538 | fi |
---|
| 539 | |
---|
| 540 | # Si le rep de suivi n'existe pas, on le créé. |
---|
| 541 | if [ ! -d ${MonitoringDir} ] |
---|
| 542 | then |
---|
[1910] | 543 | mkdir -p ${MonitoringDir} |
---|
[1822] | 544 | fi |
---|
| 545 | |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | function generalMonitoring |
---|
| 549 | { |
---|
| 550 | # Si l'etape courante a ete executee (correctement), on sort du script appelant cette fonction |
---|
| 551 | |
---|
| 552 | # nom du présent prog (pour gestion des erreurs) |
---|
| 553 | PROGNAME="DEM_utilities.sh" ######### |
---|
[1835] | 554 | |
---|
[1822] | 555 | currentStep=${1} |
---|
| 556 | stepMsg=`echo $currentStep | grep -e '^.*\.sh-->OK$' | wc -l ` |
---|
[1835] | 557 | if [ "x${stepMsg}" == "x0" ] |
---|
[1822] | 558 | then |
---|
| 559 | DEM_errorSend "${PROGNAME}:${LINENO}:Le nom de l'etape courante n'est pas au bon format !" |
---|
| 560 | fi |
---|
| 561 | |
---|
| 562 | currentStepScriptName=`echo $currentStep | sed 's;\.sh-->OK;;' ` |
---|
| 563 | # si le fichier de suivi general n'existe pas, il n'y a pas eu de passage de script de liste avant. |
---|
| 564 | # ==> on sort normalement |
---|
| 565 | if [ ! -e ${generalMonitorFile} ] |
---|
| 566 | then |
---|
| 567 | return 0 |
---|
| 568 | fi |
---|
| 569 | |
---|
| 570 | currentStepPassed=`grep ${currentStep} ${generalMonitorFile} | wc -l ` |
---|
| 571 | if [ "x${currentStepPassed}" != "x0" ] |
---|
| 572 | then |
---|
| 573 | echo "${currentStepScriptName} a deja ete passee ..." |
---|
| 574 | exit 0 |
---|
| 575 | fi |
---|
| 576 | |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | function createListingMonitoring_Check |
---|
| 580 | { |
---|
| 581 | |
---|
| 582 | # La presence de createListingOK.txt dans le sous rep (associe a un rep de param_AC.txt) du rep de suivi |
---|
| 583 | # indique que le bon deroulement de l'action de create_listing.sh sur le repertoire de param_AC.txt |
---|
| 584 | DIR=$(basename ${1}) |
---|
| 585 | MonitSubDir=${MonitoringDir}/${DIR} |
---|
| 586 | |
---|
| 587 | createListingOK=${MonitSubDir}/createListingOK.txt |
---|
| 588 | |
---|
| 589 | if [ -e $createListingOK ] |
---|
| 590 | then |
---|
| 591 | echo "create_listing a deja ete passe pour ${DIR}..." |
---|
| 592 | exit 0 |
---|
| 593 | fi |
---|
| 594 | |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | function createListingMonitoring_OK |
---|
| 598 | { |
---|
| 599 | |
---|
| 600 | # A partir du nom du rep courant (contenant des res de simulation), creation d'un sous rep de suivi |
---|
| 601 | DIR=$(basename ${1}) |
---|
| 602 | MonitSubDir=${MonitoringDir}/${DIR} |
---|
| 603 | mkdir $MonitSubDir |
---|
| 604 | |
---|
| 605 | # dans ce sous rep de suivi, creation d'un fichier dont la presence indique le bon deroulement |
---|
| 606 | # de l'action de create_listing.sh sur le repertoire en argument (celui contenant des simus) |
---|
| 607 | createListingOK=${MonitSubDir}/createListingOK.txt |
---|
| 608 | touch $createListingOK |
---|
| 609 | |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | function simuMonitoring_check |
---|
| 613 | { |
---|
| 614 | # nom du présent prog (pour gestion des erreurs) |
---|
| 615 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 616 | |
---|
| 617 | currentStep=${1} |
---|
| 618 | config=${2} |
---|
| 619 | # echo "######### simuMonitoring_check --> config:$config" |
---|
| 620 | # former le nom du fichier de suivi de la simu a partir de "config" |
---|
| 621 | getSimuMonitFileName $config |
---|
| 622 | |
---|
| 623 | # si le fichier de suivi de simu n'existe pas, il n'y a pas eu de passage de script de liste avant. |
---|
| 624 | # ==> on sort normalement |
---|
| 625 | if [ ! -e ${simuMonitoringFile} ] |
---|
| 626 | then |
---|
| 627 | return 0 |
---|
| 628 | fi |
---|
| 629 | |
---|
| 630 | stepMsg=`echo $currentStep | grep -e '^.*\.sh-->OK$' | wc -l ` |
---|
| 631 | if [ "x{stepMsg}" == "x0" ] |
---|
| 632 | then |
---|
| 633 | DEM_errorSend "${PROGNAME}:${LINENO}:Le nom de l'etape courante n'est pas au bon format !" |
---|
| 634 | fi |
---|
| 635 | |
---|
| 636 | currentStepScriptName=`echo $currentStep | sed 's;\.sh-->OK;;' ` |
---|
| 637 | |
---|
| 638 | currentStepPassed=`grep ${currentStep} ${simuMonitoringFile} | wc -l ` |
---|
| 639 | |
---|
| 640 | # echo "######### simuMonitoring_check --> currentStep:$currentStep" |
---|
| 641 | # echo "######### simuMonitoring_check --> simuMonitoringFile:$simuMonitoringFile" |
---|
| 642 | # echo "######### simuMonitoring_check --> currentStepPassed:$currentStepPassed" |
---|
| 643 | if [ "x${currentStepPassed}" != "x0" ] |
---|
| 644 | then |
---|
| 645 | echo "${currentStepScriptName} a deja ete passee ..." |
---|
| 646 | # echo "-----------------------------------------------------------------------------" |
---|
| 647 | exit 0 |
---|
| 648 | fi |
---|
| 649 | |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | function simuMonitoring_OK |
---|
| 653 | { |
---|
| 654 | currentStep=${1} |
---|
| 655 | config=${2} |
---|
| 656 | # echo "######### simuMonitoring_OK --> config:$config" |
---|
| 657 | # former le nom du fichier de suivi de la simu a partir de "config" |
---|
| 658 | getSimuMonitFileName $config |
---|
| 659 | |
---|
| 660 | echo $currentStep >> $simuMonitoringFile |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | function getSimuMonitFileName |
---|
| 664 | { |
---|
| 665 | # nom du présent prog (pour gestion des erreurs) |
---|
| 666 | PROGNAME="DEM_utilities.sh" ######### |
---|
| 667 | |
---|
| 668 | config=${1} |
---|
| 669 | # echo "######### getSimuMonitFileName --> config:$config" |
---|
| 670 | configBaseName=$(basename ${config}) |
---|
| 671 | |
---|
| 672 | # On cherche dans quel sous rep du rep de suivi on va chercher le fichier de suivi de la simu |
---|
| 673 | listMonitSubDir=`ls -l ${MonitoringDir} | grep -e '^d' | awk '{print $NF}' ` |
---|
| 674 | |
---|
| 675 | # echo "######### getSimuMonitFileName --> listMonitSubDir:$listMonitSubDir" |
---|
| 676 | |
---|
| 677 | searchedDir= |
---|
| 678 | for dir in $listMonitSubDir |
---|
| 679 | do |
---|
| 680 | found=`echo $config | grep "/${dir}/" | wc -l ` |
---|
| 681 | if [ "x${found}" != "x0" ] |
---|
| 682 | then |
---|
| 683 | searchedDir=$dir |
---|
| 684 | break |
---|
| 685 | fi |
---|
| 686 | done |
---|
| 687 | |
---|
| 688 | if [ "x$searchedDir" == "x" ] |
---|
| 689 | then |
---|
| 690 | DEM_errorSend "${PROGNAME}:${LINENO}:Sous rep de suivi non trouve !" |
---|
| 691 | fi |
---|
| 692 | |
---|
| 693 | # On forme le nom du fichier de suivi pour la simu courante |
---|
| 694 | # ... on debarasse config du fichier de config |
---|
| 695 | repConfig=$(dirname $config) |
---|
| 696 | # ... on supprime du path tout ce qui est devant le nom du sous rep |
---|
| 697 | simu=`echo $repConfig | sed "s;^.*/$searchedDir;$searchedDir;" ` |
---|
| 698 | # ... remplacement des "/" par des "_#_" (les "/" ne sont pas acceptes dans les noms de fichiers) |
---|
| 699 | simuMonitoringFile=`echo $simu | sed 's;/;_#_;g' ` |
---|
| 700 | # ... On rajoute un ".txt" a la fin du nom de fichier |
---|
| 701 | simuMonitoringFile="${simuMonitoringFile}.txt" |
---|
| 702 | |
---|
| 703 | simuMonitoringFile="${MonitoringDir}/${searchedDir}/${simuMonitoringFile}" |
---|
| 704 | } |
---|
| 705 | |
---|
[1849] | 706 | |
---|
| 707 | function getDateMilliSeconds |
---|
| 708 | { |
---|
| 709 | test=`date +%s%N` |
---|
| 710 | testnum=${#test} |
---|
| 711 | millisec=${test:0:$testnum-6} |
---|
| 712 | echo "$millisec" |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | function getTimeDiffSeconds |
---|
| 716 | { |
---|
| 717 | startTimeMilliSec=$1 |
---|
| 718 | endTimeMilliSec=$( getDateMilliSeconds ) |
---|
| 719 | |
---|
| 720 | diffMilliSec=$(( $endTimeMilliSec - $startTimeMilliSec )) |
---|
| 721 | |
---|
| 722 | diffSeconds=$(awk 'BEGIN { print '$diffMilliSec'/'1000' }') |
---|
| 723 | echo "$diffSeconds" |
---|
| 724 | |
---|
| 725 | } |
---|
| 726 | |
---|
[1822] | 727 | # gpdebug : fin ##################################################################################### |
---|
| 728 | |
---|