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