1 | #!/bin/bash |
---|
2 | |
---|
3 | |
---|
4 | listToProcessFile="${1}" |
---|
5 | |
---|
6 | |
---|
7 | |
---|
8 | switchtotar=0 # gpdebug : a modifier --> s'occuper des options du script orig enlarge.sh |
---|
9 | maxtries=3 |
---|
10 | |
---|
11 | #------------------------------------------------------ |
---|
12 | # export INPUT_DMF_DATA=${SCRATCHDIR}/datasLabo/dataDMNFS_simple1 |
---|
13 | export INPUT_DMF_DATA=${SCRATCHDIR}/dataDMNFS_FromTitane |
---|
14 | |
---|
15 | # export OUTPUT_STORE=${SCRATCHDIR}/PSEUDO_DMNFS_STORE |
---|
16 | export OUTPUT_STORE=${SCRATCHDIR}/dataDMNFS_FromTitane_STORE |
---|
17 | |
---|
18 | # export OUTPUT_WORK=${SCRATCHDIR}/PSEUDO_DMNFS_WORK |
---|
19 | export OUTPUT_WORK=${SCRATCHDIR}/dataDMNFS_FromTitane_WORK |
---|
20 | |
---|
21 | export IGCM_DEM=${SCRATCHDIR}/IGCM_DEM |
---|
22 | |
---|
23 | dirin=$INPUT_DMF_DATA |
---|
24 | dirout=$OUTPUT_STORE |
---|
25 | dirout_work=$OUTPUT_WORK |
---|
26 | |
---|
27 | export JOB_DIR=${LS_SUBCWD:-${PWD}} |
---|
28 | export EXE_DIR=${JOB_DIR} |
---|
29 | source ${EXE_DIR}/DEM_utilities.sh |
---|
30 | #------------------------------------------------------ |
---|
31 | |
---|
32 | dirPathOfListFile=$( dirname $listToProcessFile ) |
---|
33 | dirnameOfListFile=$( basename $dirPathOfListFile ) |
---|
34 | |
---|
35 | echo "dirnameOfListFile=${dirnameOfListFile}|" |
---|
36 | |
---|
37 | dirOK=0 |
---|
38 | |
---|
39 | if [ "$dirnameOfListFile" != "output_ncrcat" ] |
---|
40 | then |
---|
41 | dirOK=$(( $dirOK || 0 )) |
---|
42 | else |
---|
43 | dirOK=$(( $dirOK || 1 )) |
---|
44 | fi |
---|
45 | |
---|
46 | if [ "$dirnameOfListFile" != "output_tar" ] |
---|
47 | then |
---|
48 | dirOK=$(( $dirOK || 0 )) |
---|
49 | else |
---|
50 | dirOK=$(( $dirOK || 1 )) |
---|
51 | fi |
---|
52 | |
---|
53 | if [ "$dirnameOfListFile" != "restart_tar" ] |
---|
54 | then |
---|
55 | dirOK=$(( $dirOK || 0 )) |
---|
56 | else |
---|
57 | dirOK=$(( $dirOK || 1 )) |
---|
58 | fi |
---|
59 | |
---|
60 | if [ "$dirnameOfListFile" != "store_cp" ] |
---|
61 | then |
---|
62 | dirOK=$(( $dirOK || 0 )) |
---|
63 | else |
---|
64 | dirOK=$(( $dirOK || 1 )) |
---|
65 | fi |
---|
66 | |
---|
67 | if [ "$dirnameOfListFile" != "work_cp" ] |
---|
68 | then |
---|
69 | dirOK=$(( $dirOK || 0 )) |
---|
70 | else |
---|
71 | dirOK=$(( $dirOK || 1 )) |
---|
72 | fi |
---|
73 | |
---|
74 | if [ "$dirnameOfListFile" != "debug_tar" ] |
---|
75 | then |
---|
76 | dirOK=$(( $dirOK || 0 )) |
---|
77 | else |
---|
78 | dirOK=$(( $dirOK || 1 )) |
---|
79 | fi |
---|
80 | |
---|
81 | if [ "$dirnameOfListFile" != "other_tar" ] |
---|
82 | then |
---|
83 | dirOK=$(( $dirOK || 0 )) |
---|
84 | else |
---|
85 | dirOK=$(( $dirOK || 1 )) |
---|
86 | fi |
---|
87 | |
---|
88 | # echo "dirOK=$dirOK" |
---|
89 | |
---|
90 | if [ "$dirOK" == "0" ] |
---|
91 | then |
---|
92 | echo "probleme : le rep du fichier liste est mauvais 2." # gpdebug : a modifier |
---|
93 | exit 1 |
---|
94 | fi |
---|
95 | |
---|
96 | |
---|
97 | function find_varstoexclude { |
---|
98 | nbfile=0 |
---|
99 | for file in `cat $1` ; do |
---|
100 | # ncdump -h ${file} | gawk '{if (match($0, /(byte|char|short|int|float|double) (.*)\(/, arr)) print arr[2] }' >> tmp_$$.txt |
---|
101 | ncdump -h ${file} | grep -Ew "byte|char|short|int|float|double" | awk -F\( '{split($1,a," ") ; split($2,b,")") ; if (a[2] != b[1]) print a[2]}' >> tmp_$$.txt |
---|
102 | let nbfile=nbfile+1 |
---|
103 | done |
---|
104 | |
---|
105 | varstoexclude=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if ($1 != nbfile) {print $2}}' | paste -s -d','` |
---|
106 | varstoexcludefiltered=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if (($1 != nbfile) && !(match($2, /t_inst_(.*)/))) {print $2}}' | paste -s -d','` |
---|
107 | nbvars=`echo $varstoexcludefiltered | gawk -F',' '{print NF}'` |
---|
108 | |
---|
109 | rm -f tmp_$$.txt |
---|
110 | |
---|
111 | return 0 |
---|
112 | } |
---|
113 | |
---|
114 | # gpdebug : pour test showPackProgress.sh ************************* |
---|
115 | export RANDOM=$$ |
---|
116 | |
---|
117 | function gives_0_or_1 |
---|
118 | { |
---|
119 | bit=-1 |
---|
120 | let "bit = RANDOM % 2" |
---|
121 | echo $bit |
---|
122 | } |
---|
123 | |
---|
124 | resultCmd= |
---|
125 | # gpdebug : ****************************** fin ******************** |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | # rep de simu : celui contenant le rep qui contient la liste |
---|
131 | PATH_SIMU=$( dirname $dirPathOfListFile ) |
---|
132 | set=$listToProcessFile |
---|
133 | |
---|
134 | |
---|
135 | if [ "$dirnameOfListFile" == "output_ncrcat" ] |
---|
136 | then |
---|
137 | #----------------------------------- |
---|
138 | echo "#-------------------" |
---|
139 | echo "Set: $set" |
---|
140 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
141 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
142 | statusfile=${set%%.list}.status |
---|
143 | logfile=${set%%.list}_${datestr}.log |
---|
144 | |
---|
145 | #----------------------------------- |
---|
146 | # Create status file if not exists |
---|
147 | if [ ! -e $statusfile ] ; then |
---|
148 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
149 | fi |
---|
150 | |
---|
151 | #----------------------------------- |
---|
152 | # Switch to tar command |
---|
153 | if [ $switchtotar -eq 1 ] ; then |
---|
154 | echo "====> DELEGATE to tar command with option --switchtotar" |
---|
155 | echo "DELEGATE to tar command with option --switchtotar" >> $statusfile |
---|
156 | mv $set $PATH_SIMU/output_tar |
---|
157 | exit 0 |
---|
158 | fi |
---|
159 | |
---|
160 | #----------------------------------- |
---|
161 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
162 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
163 | printf "====> " |
---|
164 | tail -1 $statusfile |
---|
165 | exit 0 # gpdebug : modif |
---|
166 | fi |
---|
167 | |
---|
168 | #----------------------------------- |
---|
169 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
170 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
171 | echo "Nb of tries: $nbtries" |
---|
172 | |
---|
173 | #----------------------------------- |
---|
174 | # Set output file name from list name |
---|
175 | |
---|
176 | fileout1=$( basename $set ) |
---|
177 | fileout=${fileout1%.list} |
---|
178 | |
---|
179 | filefirst=`head -n 1 $set` |
---|
180 | diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"` |
---|
181 | |
---|
182 | outputfile=$diroutputfile/${fileout} |
---|
183 | mkdir -p $diroutputfile |
---|
184 | echo "Output file to write: $outputfile" |
---|
185 | |
---|
186 | #----------------------------------- |
---|
187 | # Find variables to exclude to have homogeneous files (always exclude 't_inst_.*') |
---|
188 | extratar=0 |
---|
189 | find_varstoexclude $set |
---|
190 | if [ $nbvars -eq 0 ] ; then |
---|
191 | varstoexclude="t_inst_.*" |
---|
192 | else |
---|
193 | # There are others variables than 't_inst_.*' so an extra tar file will be created |
---|
194 | varstoexclude="t_inst_.*,$varstoexcludefiltered" |
---|
195 | extratar=1 |
---|
196 | # Copy to output_tar directory |
---|
197 | echo "====> COPY to tar command because find other variables ($varstoexcludefiltered) than t_inst_*" |
---|
198 | echo "COPY to tar command because find other variables ($varstoexcludefiltered) than t_inst_*" >> $statusfile |
---|
199 | cp $set $PATH_SIMU/output_tar |
---|
200 | fi |
---|
201 | |
---|
202 | #----------------------------------- |
---|
203 | # Try 2 times before fire "FAILED" |
---|
204 | ncrcatcmd=ncrcat |
---|
205 | ncrcatoptions="--md5_digest" |
---|
206 | # ncrcatoptions="" |
---|
207 | |
---|
208 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
209 | resCmd=0 |
---|
210 | cat $set | $ncrcatcmd $ncrcatoptions -O -x -v $varstoexclude -o $outputfile > $logfile 2>&1 # gpdebug : a retablir |
---|
211 | resCmd=$? |
---|
212 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
213 | |
---|
214 | # resultCmd=$( gives_0_or_1 ) |
---|
215 | # resultCmd=1 |
---|
216 | # if [ $resultCmd -eq 0 ] ; then |
---|
217 | if [ $resCmd -eq 0 ] ; then |
---|
218 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
219 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
220 | echo "DONE ; $datestr1 ; $datestr2 ; cat $set | $ncrcatcmd $ncrcatoptions -O -x -v '$varstoexclude' -o $outputfile ; $logfile ; $extratar" >> $statusfile |
---|
221 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 2)" |
---|
222 | echo "COMPLETED at try #$nbtries (at 1st shot on 2)" >> $statusfile |
---|
223 | else |
---|
224 | # Add --md5_digest |
---|
225 | rm -f $outputfile*ncrcat.tmp |
---|
226 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
227 | resCmd=0 |
---|
228 | cat $set | $ncrcatcmd $ncrcatoptions -O -x -v $varstoexclude -o $outputfile > $logfile 2>&1 # gpdebug : a retablir |
---|
229 | resCmd=$? |
---|
230 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
231 | # resultCmd=$( gives_0_or_1 ) |
---|
232 | # resultCmd=1 |
---|
233 | # if [ $resultCmd -eq 0 ] ; then |
---|
234 | if [ $resCmd -eq 0 ] ; then |
---|
235 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
236 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
237 | echo "DONE ; $datestr1 ; $datestr2 ; cat $set | $ncrcatcmd $ncrcatoptions -O -x -v '$varstoexclude' -o $outputfile ; $logfile ; $extratar" >> $statusfile |
---|
238 | echo "====> COMPLETED at try #$nbtries (at 2nd shot on 2)" |
---|
239 | echo "COMPLETED at try #$nbtries (at 2nd shot on 2)" >> $statusfile |
---|
240 | else |
---|
241 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
242 | rm -f $outputfile*ncrcat.tmp |
---|
243 | echo "====> FAILED at try #$nbtries" |
---|
244 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; cat $set | $ncrcatcmd $ncrcatoptions -O -x -v '$varstoexclude' -o $outputfile ; $logfile ; $extratar" >> $statusfile |
---|
245 | if [ $nbtries -ge $maxtries ] ; then |
---|
246 | echo "====> DELEGATE to tar command after $nbtries tries (maxtries=$maxtries)" |
---|
247 | echo "DELEGATE to tar command after $nbtries tries (maxtries=$maxtries)" >> $statusfile |
---|
248 | cp $set $PATH_SIMU/output_tar # gpdebug : a retablir |
---|
249 | fi |
---|
250 | fi |
---|
251 | fi |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | fi |
---|
256 | |
---|
257 | |
---|
258 | #------------------------------------------------------ |
---|
259 | if [ "$dirnameOfListFile" == "output_tar" ] |
---|
260 | then |
---|
261 | |
---|
262 | #----------------------------------- |
---|
263 | echo "#-------------------" |
---|
264 | echo "Set: $set" |
---|
265 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
266 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
267 | statusfile=${set%%.list}.status |
---|
268 | logfile=${set%%.list}_${datestr}.log |
---|
269 | |
---|
270 | #----------------------------------- |
---|
271 | # Create status file if not exists |
---|
272 | if [ ! -e $statusfile ] ; then |
---|
273 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
274 | fi |
---|
275 | |
---|
276 | #----------------------------------- |
---|
277 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
278 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
279 | printf "====> " |
---|
280 | tail -1 $statusfile |
---|
281 | exit 0 |
---|
282 | fi |
---|
283 | |
---|
284 | #----------------------------------- |
---|
285 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
286 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
287 | # echo "Nb of tries: $nbtries" |
---|
288 | |
---|
289 | #----------------------------------- |
---|
290 | # Set output file name from list name |
---|
291 | |
---|
292 | fileout1=$( basename $set ) |
---|
293 | fileout=${fileout1%.list}.tar |
---|
294 | |
---|
295 | filefirst=`head -n 1 $set` |
---|
296 | dirinputfile=`dirname $filefirst` |
---|
297 | diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"` |
---|
298 | |
---|
299 | outputfile=$diroutputfile/${fileout} |
---|
300 | mkdir -p $diroutputfile |
---|
301 | echo "Output file to write: $outputfile" |
---|
302 | |
---|
303 | #----------------------------------- |
---|
304 | # Try 1 time before fire "FAILED" |
---|
305 | # Waiting for CCRT command |
---|
306 | tarcmd=tar |
---|
307 | taroptions="--format=posix -W -cf" |
---|
308 | |
---|
309 | cd $dirinputfile |
---|
310 | |
---|
311 | set_local=$set".local" |
---|
312 | for file in $( cat $set) ; do |
---|
313 | basename $file >> $set".local" |
---|
314 | done |
---|
315 | |
---|
316 | # #----------------------------------- |
---|
317 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
318 | resCmd=0 |
---|
319 | $tarcmd $taroptions $outputfile --dereference --files-from $set.local > $logfile 2>&1 # gpdebug : a retablir |
---|
320 | resCmd=$? |
---|
321 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
322 | |
---|
323 | # resultCmd=$( gives_0_or_1 ) |
---|
324 | # if [ $resultCmd -eq 0 ] ; then |
---|
325 | if [ $resCmd -eq 0 ] ; then |
---|
326 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
327 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
328 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
329 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
330 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
331 | else |
---|
332 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
333 | echo "====> FAILED at try #$nbtries" |
---|
334 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
335 | |
---|
336 | fi |
---|
337 | rm -f $set".local" |
---|
338 | #----------------------------------- |
---|
339 | |
---|
340 | fi |
---|
341 | |
---|
342 | |
---|
343 | #------------------------------------------------------ |
---|
344 | if [ "$dirnameOfListFile" == "restart_tar" ] |
---|
345 | then |
---|
346 | #----------------------------------- |
---|
347 | echo "#-------------------" |
---|
348 | echo "Set: $set" |
---|
349 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
350 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
351 | statusfile=${set%%.list}.status |
---|
352 | logfile=${set%%.list}_${datestr}.log |
---|
353 | |
---|
354 | #----------------------------------- |
---|
355 | # Create status file if not exists |
---|
356 | if [ ! -e $statusfile ] ; then |
---|
357 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
358 | fi |
---|
359 | |
---|
360 | #----------------------------------- |
---|
361 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
362 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
363 | printf "====> " |
---|
364 | tail -1 $statusfile |
---|
365 | exit 0 |
---|
366 | fi |
---|
367 | |
---|
368 | #----------------------------------- |
---|
369 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
370 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
371 | # echo "Nb of tries: $nbtries" |
---|
372 | |
---|
373 | #----------------------------------- |
---|
374 | # Set output file name from list name |
---|
375 | dirin1=$PATH_SIMU/RESTART |
---|
376 | dirin2=${dirin1##${IGCM_DEM}} |
---|
377 | dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )} |
---|
378 | diroutputfile=${OUTPUT_STORE}${dirin3} |
---|
379 | fileout1=$( basename $set ) |
---|
380 | fileout=${fileout1%.list}.tar |
---|
381 | outputfile=$diroutputfile/${fileout} |
---|
382 | mkdir -p $diroutputfile |
---|
383 | echo "Output file to write: $outputfile" |
---|
384 | |
---|
385 | #----------------------------------- |
---|
386 | # Try 1 time before fire "FAILED" |
---|
387 | # Waiting for CCRT command |
---|
388 | tarcmd=tar |
---|
389 | taroptions="--format=posix -W -cf" |
---|
390 | |
---|
391 | cd $dirin1 |
---|
392 | # ls |
---|
393 | |
---|
394 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
395 | resCmd=0 |
---|
396 | $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 # gpdebug : a retablir |
---|
397 | resCmd=$? |
---|
398 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
399 | |
---|
400 | # resultCmd=$( gives_0_or_1 ) |
---|
401 | # if [ $resultCmd -eq 0 ] ; then |
---|
402 | if [ $resCmd -eq 0 ] ; then |
---|
403 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
404 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
405 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
406 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
407 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
408 | else |
---|
409 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
410 | echo "====> FAILED at try #$nbtries" |
---|
411 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
412 | |
---|
413 | fi |
---|
414 | |
---|
415 | #----------------------------------- |
---|
416 | |
---|
417 | fi |
---|
418 | |
---|
419 | #------------------------------------------------------ |
---|
420 | if [ "$dirnameOfListFile" == "debug_tar" ] |
---|
421 | then |
---|
422 | |
---|
423 | #----------------------------------- |
---|
424 | echo "#-------------------" |
---|
425 | echo "Set: $set" |
---|
426 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
427 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
428 | statusfile=${set%%.list}.status |
---|
429 | logfile=${set%%.list}_${datestr}.log |
---|
430 | |
---|
431 | #----------------------------------- |
---|
432 | # Create status file if not exists |
---|
433 | if [ ! -e $statusfile ] ; then |
---|
434 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
435 | fi |
---|
436 | |
---|
437 | #----------------------------------- |
---|
438 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
439 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
440 | printf "====> " |
---|
441 | tail -1 $statusfile |
---|
442 | exit 0 |
---|
443 | fi |
---|
444 | |
---|
445 | #----------------------------------- |
---|
446 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
447 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
448 | # echo "Nb of tries: $nbtries" |
---|
449 | |
---|
450 | #----------------------------------- |
---|
451 | # Set output file name from list name |
---|
452 | dirin1=$PATH_SIMU/DEBUG |
---|
453 | dirin2=${dirin1##${IGCM_DEM}} |
---|
454 | dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )} |
---|
455 | diroutputfile=${OUTPUT_STORE}${dirin3} |
---|
456 | fileout1=$( basename $set ) |
---|
457 | fileout=${fileout1%.list}.tar |
---|
458 | outputfile=$diroutputfile/${fileout} |
---|
459 | mkdir -p $diroutputfile |
---|
460 | echo "Output file to write: $outputfile" |
---|
461 | |
---|
462 | #----------------------------------- |
---|
463 | # Try 1 time before fire "FAILED" |
---|
464 | # Waiting for CCRT command |
---|
465 | tarcmd=tar |
---|
466 | taroptions="--format=posix -W -cf" |
---|
467 | |
---|
468 | cd $dirin1 |
---|
469 | # ls |
---|
470 | resCmd=0 |
---|
471 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
472 | $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 # gpdebug : a retablir |
---|
473 | resCmd=$? |
---|
474 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
475 | |
---|
476 | # resultCmd=$( gives_0_or_1 ) |
---|
477 | # if [ $resultCmd -eq 0 ] ; then |
---|
478 | if [ $resCmd -eq 0 ] ; then |
---|
479 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
480 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
481 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
482 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
483 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
484 | else |
---|
485 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
486 | echo "====> FAILED at try #$nbtries" |
---|
487 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
488 | |
---|
489 | fi |
---|
490 | |
---|
491 | #----------------------------------- |
---|
492 | |
---|
493 | fi |
---|
494 | |
---|
495 | #------------------------------------------------------ |
---|
496 | if [ "$dirnameOfListFile" == "store_cp" ] |
---|
497 | then |
---|
498 | #----------------------------------- |
---|
499 | echo "#-------------------" |
---|
500 | echo "Set: $set" |
---|
501 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
502 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
503 | statusfile=${set%%.list}.status |
---|
504 | logfile=${set%%.list}_${datestr}.log |
---|
505 | |
---|
506 | #----------------------------------- |
---|
507 | # Create status file if not exists |
---|
508 | if [ ! -e $statusfile ] ; then |
---|
509 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
510 | fi |
---|
511 | |
---|
512 | #----------------------------------- |
---|
513 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
514 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
515 | printf "====> " |
---|
516 | tail -1 $statusfile |
---|
517 | exit 0 |
---|
518 | fi |
---|
519 | |
---|
520 | #----------------------------------- |
---|
521 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
522 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
523 | # echo "Nb of tries: $nbtries" |
---|
524 | |
---|
525 | meantime=0 |
---|
526 | resCmd=0 |
---|
527 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
528 | #----------------------------------- |
---|
529 | # Set output file name from first and last files from the current set |
---|
530 | for file in $( cat $set) ; do |
---|
531 | |
---|
532 | diroutputfile=`dirname $file | sed -e "s%$dirin%$dirout%"` |
---|
533 | mkdir -p $diroutputfile |
---|
534 | echo "Output file to write: $diroutputfile/$( basename $file )" |
---|
535 | |
---|
536 | #----------------------------------- |
---|
537 | # Try 1 time before fire "FAILED" |
---|
538 | # Waiting for CCRT command |
---|
539 | cpcmd="cp " |
---|
540 | cpoptions="-rf" |
---|
541 | $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1 # gpdebug : a retablir |
---|
542 | resCmd=$(( $resCmd || $? )) |
---|
543 | done |
---|
544 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time |
---|
545 | |
---|
546 | # resultCmd=$( gives_0_or_1 ) |
---|
547 | # if [ $resultCmd -eq 0 ] ; then |
---|
548 | if [ $resCmd -eq 0 ] ; then |
---|
549 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
550 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
551 | echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
552 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
553 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
554 | else |
---|
555 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
556 | echo "====> FAILED at try #$nbtries" |
---|
557 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
558 | |
---|
559 | fi |
---|
560 | |
---|
561 | #----------------------------------- |
---|
562 | |
---|
563 | fi |
---|
564 | |
---|
565 | #------------------------------------------------------ |
---|
566 | if [ "$dirnameOfListFile" == "work_cp" ] |
---|
567 | then |
---|
568 | #----------------------------------- |
---|
569 | echo "#-------------------" |
---|
570 | echo "Set: $set" |
---|
571 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
572 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
573 | statusfile=${set%%.list}.status |
---|
574 | logfile=${set%%.list}_${datestr}.log |
---|
575 | |
---|
576 | #----------------------------------- |
---|
577 | # Create status file if not exists |
---|
578 | if [ ! -e $statusfile ] ; then |
---|
579 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
580 | fi |
---|
581 | |
---|
582 | #----------------------------------- |
---|
583 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
584 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
585 | printf "====> " |
---|
586 | tail -1 $statusfile |
---|
587 | exit 0 |
---|
588 | fi |
---|
589 | |
---|
590 | #----------------------------------- |
---|
591 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
592 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
593 | # echo "Nb of tries: $nbtries" |
---|
594 | |
---|
595 | meantime=0 |
---|
596 | resCmd=0 |
---|
597 | startTime=$( getDateMilliSeconds ) # gpdebug : time |
---|
598 | #----------------------------------- |
---|
599 | # Set output file name from first and last files from the current set |
---|
600 | for file in $( cat $set) ; do |
---|
601 | |
---|
602 | diroutputfile=`dirname $file | sed -e "s%$dirin%$dirout_work%"` |
---|
603 | mkdir -p $diroutputfile |
---|
604 | echo "Output file to write: $diroutputfile/$( basename $file )" |
---|
605 | |
---|
606 | #----------------------------------- |
---|
607 | # Try 1 time before fire "FAILED" |
---|
608 | # Waiting for CCRT command |
---|
609 | cpcmd="cp " |
---|
610 | cpoptions="-rf" |
---|
611 | $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1 # gpdebug : a retablir |
---|
612 | resCmd=$(( $resCmd || $? )) |
---|
613 | done |
---|
614 | meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : timeS |
---|
615 | # resultCmd=$( gives_0_or_1 ) |
---|
616 | # if [ $resultCmd -eq 0 ] ; then |
---|
617 | if [ $resCmd -eq 0 ] ; then |
---|
618 | sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time |
---|
619 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
620 | echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
621 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
622 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
623 | else |
---|
624 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
625 | echo "====> FAILED at try #$nbtries" |
---|
626 | echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
627 | |
---|
628 | fi |
---|
629 | |
---|
630 | #----------------------------------- |
---|
631 | |
---|
632 | fi |
---|
633 | |
---|
634 | |
---|
635 | |
---|
636 | |
---|
637 | |
---|
638 | |
---|
639 | |
---|
640 | |
---|
641 | |
---|
642 | |
---|
643 | |
---|
644 | |
---|
645 | |
---|