source: TOOLS/PACK_IPSL/process_list.sh @ 1862

Last change on this file since 1862 was 1853, checked in by gpincka, 12 years ago

principalement : enchainement du launcher parallele + gestion reprise du code parallele

  • Property svn:executable set to *
File size: 22.3 KB
Line 
1#!/bin/bash
2
3
4listToProcessFile="${1}"
5
6
7
8switchtotar=0 # gpdebug : a modifier --> s'occuper des options du script orig enlarge.sh
9maxtries=3
10
11# On renseigne les variables d'environnement
12. load_ipslPack_env.sh
13
14dirin=$INPUT_DMF_DATA
15dirout=$OUTPUT_STORE
16dirout_work=$OUTPUT_WORK
17
18export JOB_DIR=${LS_SUBCWD:-${PWD}}
19export EXE_DIR=${JOB_DIR}
20source ${EXE_DIR}/DEM_utilities.sh
21#------------------------------------------------------
22
23baseNameOfListFile=$( basename $listToProcessFile )
24dirPathOfListFile=$( dirname  $listToProcessFile )
25dirnameOfListFile=$( basename $dirPathOfListFile )
26
27echo "dirnameOfListFile ==> $dirnameOfListFile"
28
29
30if ( \
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" ]
41then
42        echo "probleme : le rep du fichier liste est mauvais." # gpdebug : a modifier
43        exit 1
44fi
45
46
47function find_varstoexclude {
48nbfile=0
49for 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
53done
54
55varstoexclude=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if ($1 != nbfile) {print $2}}' | paste -s -d','`
56varstoexcludefiltered=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if (($1 != nbfile) && !(match($2, /t_inst_(.*)/))) {print $2}}' | paste -s -d','`
57nbvars=`echo $varstoexcludefiltered | gawk -F',' '{print NF}'`
58
59rm -f tmp_$$.txt
60
61return 0
62}
63
64# gpdebug : pour test showPackProgress.sh *************************
65export RANDOM=$$
66
67function gives_0_or_1
68{
69   bit=-1
70   let "bit = RANDOM % 2"
71   echo $bit
72}
73
74resultCmd=
75# gpdebug : ****************************** fin ********************
76
77
78
79
80# rep de simu : celui contenant le rep qui contient la liste
81PATH_SIMU=$( dirname  $dirPathOfListFile )
82set=$listToProcessFile
83
84
85if [ "$dirnameOfListFile" == "output_ncrcat" ]
86then
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 0
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                        exit 1
205                fi
206        fi
207
208
209
210fi
211
212
213#------------------------------------------------------
214if [ "$dirnameOfListFile" == "output_tar" ]
215then
216
217        #-----------------------------------
218        echo "#-------------------"
219        echo "Set: $set"
220        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
221        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
222        statusfile=${set%%.list}.status
223        logfile=${set%%.list}_${datestr}.log
224
225        #-----------------------------------
226        # Create status file if not exists
227        if [ ! -e $statusfile ] ; then
228                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
229        fi
230
231        #-----------------------------------
232        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
233        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
234                printf "====> "
235                tail -1 $statusfile
236                exit 0
237        fi
238
239        #-----------------------------------
240        # nbtries = number of lines from status file (first comment line gives 1 for the first try)
241        nbtries=`wc -l $statusfile | cut -d' ' -f1`             
242        # echo "Nb of tries: $nbtries"
243
244        #-----------------------------------
245        # Set output file name from list name
246
247        fileout1=$( basename $set )
248        fileout=${fileout1%.list}.tar
249       
250        filefirst=`head -n 1 $set`
251        dirinputfile=`dirname $filefirst`
252        diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"` 
253
254        outputfile=$diroutputfile/${fileout}
255        mkdir -p $diroutputfile
256        echo "Output file to write: $outputfile  output_tar"
257
258        #-----------------------------------
259        # Try 1 time before fire "FAILED"
260        # Waiting for CCRT command
261        tarcmd=tar
262        taroptions="--format=posix -W -cf"
263       
264        cd $dirinputfile
265
266        set_local=$set".local"
267        for file in $( cat $set) ; do
268            basename $file >> $set".local" 
269        done
270           
271#       #-----------------------------------
272        startTime=$( getDateMilliSeconds ) # gpdebug : time
273        resCmd=0
274        $tarcmd $taroptions $outputfile --dereference --files-from $set.local > $logfile 2>&1 # gpdebug : a retablir
275        resCmd=$?
276        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time
277       
278        # resultCmd=$( gives_0_or_1 )
279        # if [ $resultCmd -eq 0 ] ; then
280        if [ $resCmd -eq 0 ] ; then
281            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
282            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
283            echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile
284            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
285            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
286        else
287            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
288            echo "====> FAILED at try #$nbtries" 
289            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile
290            exit 1
291        fi
292        rm -f $set".local" 
293        #-----------------------------------
294       
295fi
296
297
298#------------------------------------------------------
299if [ "$dirnameOfListFile" == "restart_tar" ]
300then
301        #-----------------------------------
302        echo "#-------------------"
303        echo "Set: $set"
304        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
305        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
306        statusfile=${set%%.list}.status
307        logfile=${set%%.list}_${datestr}.log
308
309        #-----------------------------------
310        # Create status file if not exists
311        if [ ! -e $statusfile ] ; then
312                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
313        fi
314
315        #-----------------------------------
316        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
317        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
318                printf "====> "
319                tail -1 $statusfile
320                exit 0
321        fi
322
323        #-----------------------------------
324        # nbtries = number of lines from status file (first comment line gives 1 for the first try)
325        nbtries=`wc -l $statusfile | cut -d' ' -f1`             
326        # echo "Nb of tries: $nbtries"
327
328        #-----------------------------------
329        # Set output file name from list name
330        dirin1=$PATH_SIMU/RESTART
331        dirin2=${dirin1##${IGCM_DEM}}
332        dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )}
333        diroutputfile=${OUTPUT_STORE}${dirin3}
334        fileout1=$( basename $set )
335        fileout=${fileout1%.list}.tar
336        outputfile=$diroutputfile/${fileout}
337        mkdir -p $diroutputfile
338        echo "Output file to write: $outputfile  restart_tar"
339
340        #-----------------------------------
341        # Try 1 time before fire "FAILED"
342        # Waiting for CCRT command
343        tarcmd=tar
344        taroptions="--format=posix -W -cf"
345       
346        cd $dirin1
347#       ls
348       
349        startTime=$( getDateMilliSeconds ) # gpdebug : time
350        resCmd=0
351        $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 # gpdebug : a retablir
352        resCmd=$?
353        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time
354       
355        # resultCmd=$( gives_0_or_1 )
356        # if [ $resultCmd -eq 0 ] ; then
357        if [ $resCmd -eq 0 ] ; then
358            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
359            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
360            echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile
361            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
362            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
363        else
364            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
365            echo "====> FAILED at try #$nbtries" 
366            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile
367            exit 1
368        fi
369       
370        #-----------------------------------
371       
372fi     
373
374#------------------------------------------------------
375if [ "$dirnameOfListFile" == "debug_tar" ]
376then
377
378        #-----------------------------------
379        echo "#-------------------"
380        echo "Set: $set"
381        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
382        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
383        statusfile=${set%%.list}.status
384        logfile=${set%%.list}_${datestr}.log
385
386        #-----------------------------------
387        # Create status file if not exists
388        if [ ! -e $statusfile ] ; then
389                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
390        fi
391
392        #-----------------------------------
393        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
394        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
395                printf "====> "
396                tail -1 $statusfile
397                exit 0
398        fi
399
400        #-----------------------------------
401        # nbtries = number of lines from status file (first comment line gives 1 for the first try)
402        nbtries=`wc -l $statusfile | cut -d' ' -f1`             
403        # echo "Nb of tries: $nbtries"
404
405        #-----------------------------------
406        # Set output file name from list name
407        dirin1=$PATH_SIMU/DEBUG
408        dirin2=${dirin1##${IGCM_DEM}}
409        dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )}
410        diroutputfile=${OUTPUT_STORE}${dirin3}
411        fileout1=$( basename $set )
412        fileout=${fileout1%.list}.tar
413        outputfile=$diroutputfile/${fileout}
414        mkdir -p $diroutputfile
415        echo "Output file to write: $outputfile  debug_tar"
416
417        #-----------------------------------
418        # Try 1 time before fire "FAILED"
419        # Waiting for CCRT command
420        tarcmd=tar
421        taroptions="--format=posix -W -cf"
422       
423        cd $dirin1
424#       ls
425        resCmd=0
426        startTime=$( getDateMilliSeconds ) # gpdebug : time
427        $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 # gpdebug : a retablir
428        resCmd=$?
429        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time
430       
431        # resultCmd=$( gives_0_or_1 )
432        # if [ $resultCmd -eq 0 ] ; then
433        if [ $resCmd -eq 0 ] ; then
434            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
435            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
436            echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile
437            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
438            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
439        else
440            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
441            echo "====> FAILED at try #$nbtries" 
442            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile
443            exit 1
444        fi
445       
446        #-----------------------------------
447       
448fi
449
450#------------------------------------------------------
451if [ "$dirnameOfListFile" == "store_cp" ]
452then
453        #-----------------------------------
454        echo "#-------------------"
455        echo "Set: $set"
456        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
457        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
458        statusfile=${set%%.list}.status
459        logfile=${set%%.list}_${datestr}.log
460
461        #-----------------------------------
462        # Create status file if not exists
463        if [ ! -e $statusfile ] ; then
464                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
465        fi
466
467        #-----------------------------------
468        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
469        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
470                printf "====> "
471                tail -1 $statusfile
472                exit 0
473        fi
474
475        #-----------------------------------
476        # nbtries = number of lines from status file (first comment line gives 1 for the first try)
477        nbtries=`wc -l $statusfile | cut -d' ' -f1`             
478        # echo "Nb of tries: $nbtries"
479
480        meantime=0
481        resCmd=0
482        startTime=$( getDateMilliSeconds ) # gpdebug : time
483        #-----------------------------------
484        # Set output file name from first and last files from the current set
485        for file in $( cat $set) ; do
486         
487            diroutputfile=`dirname $file | sed -e "s%$dirin%$dirout%"`
488            mkdir -p $diroutputfile
489            echo "Output file to write: $diroutputfile/$( basename $file )  store_cp"
490           
491        #-----------------------------------
492        # Try 1 time before fire "FAILED"
493        # Waiting for CCRT command
494            cpcmd="cp "
495            cpoptions="-rf"
496            $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1 # gpdebug : a retablir
497            resCmd=$(( $resCmd || $? ))
498        done
499        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time
500       
501        # resultCmd=$( gives_0_or_1 )
502        # if [ $resultCmd -eq 0 ] ; then
503        if [ $resCmd -eq 0 ] ; then
504            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
505            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
506            echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile
507            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
508            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
509        else
510            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
511            echo "====> FAILED at try #$nbtries" 
512            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile
513            exit 1
514        fi
515       
516        #-----------------------------------
517       
518fi     
519
520#------------------------------------------------------
521if [ "$dirnameOfListFile" == "work_cp" ]
522then
523        #-----------------------------------
524        echo "#-------------------"
525        echo "Set: $set"
526        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
527        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
528        statusfile=${set%%.list}.status
529        logfile=${set%%.list}_${datestr}.log
530
531        #-----------------------------------
532        # Create status file if not exists
533        if [ ! -e $statusfile ] ; then
534                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
535        fi
536
537        #-----------------------------------
538        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
539        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
540                printf "====> "
541                tail -1 $statusfile
542                exit 0
543        fi
544
545        #-----------------------------------
546        # nbtries = number of lines from status file (first comment line gives 1 for the first try)
547        nbtries=`wc -l $statusfile | cut -d' ' -f1`             
548        # echo "Nb of tries: $nbtries"
549
550        meantime=0
551        resCmd=0
552        startTime=$( getDateMilliSeconds ) # gpdebug : time
553        #-----------------------------------
554        # Set output file name from first and last files from the current set
555        for file in $( cat $set) ; do
556         
557            diroutputfile=`dirname $file | sed -e "s%$dirin%$dirout_work%"`
558            mkdir -p $diroutputfile
559            echo "Output file to write: $diroutputfile/$( basename $file )  work_cp"
560           
561        #-----------------------------------
562        # Try 1 time before fire "FAILED"
563        # Waiting for CCRT command
564            cpcmd="cp "
565            cpoptions="-rf"
566            $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1  # gpdebug : a retablir
567            resCmd=$(( $resCmd || $? ))   
568        done
569        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : timeS
570        # resultCmd=$( gives_0_or_1 )
571        # if [ $resultCmd -eq 0 ] ; then
572        if [ $resCmd -eq 0 ] ; then
573            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
574            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
575            echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile
576            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
577            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
578        else
579            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
580            echo "====> FAILED at try #$nbtries" 
581            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile
582            exit 1
583        fi
584       
585        #-----------------------------------
586       
587fi
588
589# gpdebug : traitement des simu < 1 Go ou de type create_etat0
590#           il n'est censé n'y avoir qu'un seul fichier tar_full_simul.list par simu.
591#           d'ou le "if" et non le "for"
592# pense bete :
593#    * implication dans showPackProgress.sh (fichier status) ?
594if [ "$baseNameOfListFile" == "tar_full_simul.list" ]
595then
596        # set="${PATH_SIMU}/tar_full_simul.list" # gpdebug : foireux ?
597        #-----------------------------------
598        echo "#-------------------"
599        echo "Set: $set"
600        datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"`
601        datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
602        statusfile=${set%%.list}.status
603        logfile=${set%%.list}_${datestr}.log
604
605        #-----------------------------------
606        # Create status file if not exists
607        if [ ! -e $statusfile ] ; then
608                echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile
609        fi
610
611        #-----------------------------------
612        # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE"
613        if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then
614                printf "====> "
615                tail -1 $statusfile
616                exit 0
617        fi
618
619        #-----------------------------------
620        # Set output file name from list name
621        # echo "PATH_SIMU=$PATH_SIMU"
622        dirOfOutputFile=`echo $PATH_SIMU | sed "s;${IGCM_DEM};${OUTPUT_STORE};" `
623        fileout=${dirnameOfListFile}.tar
624        # echo "dirnameOfListFile=$dirnameOfListFile"
625        outputfile=$dirOfOutputFile/${fileout}
626        mkdir -p $dirOfOutputFile
627        echo "Output file to write: $outputfile  tar_full_simul"
628       
629        # exit 0 # a virer
630
631        #-----------------------------------
632        # Try 1 time before fire "FAILED"
633        # Waiting for CCRT command
634        tarcmd=tar
635        taroptions="--format=posix -W -cf"
636#       taroptions="--format=posix -cf"
637
638        filefirst=`head -n 1 $set`
639        dirinputfile=`dirname $filefirst`
640        cd $dirinputfile
641
642        set_local=${set%%.list}.local
643        > $set_local
644        for file in $( cat $set) ; do
645            basename $file >> $set_local 
646        done
647#       ls
648       
649        startTime=$( getDateMilliSeconds ) # gpdebug : time
650        resCmd=0
651        $tarcmd $taroptions $outputfile --dereference --files-from $set_local > $logfile 2>&1 # gpdebug : a retablir
652        resCmd=$?
653        meantime=$( getTimeDiffSeconds $startTime ) # gpdebug : time
654       
655        # resultCmd=$( gives_0_or_1 )
656        # if [ $resultCmd -eq 0 ] ; then
657        if [ $resCmd -eq 0 ] ; then
658            sed -i "1i\meantime:${meantime}" $statusfile # gpdebug : time
659            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
660            echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile
661            echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)"
662            echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile
663        else
664            datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"`
665            echo "====> FAILED at try #$nbtries" 
666            echo "FAILED at try #$nbtries ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile
667            exit 1
668        fi
669       
670        #-----------------------------------
671fi
672
673
674
675
676
677
678
679
680
681
682
Note: See TracBrowser for help on using the repository browser.