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