source: TOOLS/PACK_IPSL/enlarge_my_files.sh @ 1849

Last change on this file since 1849 was 1849, checked in by acosce, 12 years ago

Add parallel version - global double check - minor bug

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