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