1 | #!/bin/bash |
---|
2 | #------------------------------------------------------ |
---|
3 | switchtotar=0 |
---|
4 | maxtries=3 |
---|
5 | #--------------------------------------------- |
---|
6 | while [ $# -ne 0 ] |
---|
7 | do |
---|
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 " |-- with_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 " \`-- with_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 |
---|
57 | done |
---|
58 | |
---|
59 | if [ $# -lt 2 ] ; then |
---|
60 | `dirname $0`/enlarge_my_files.sh -h |
---|
61 | exit |
---|
62 | fi |
---|
63 | |
---|
64 | if [[ ! -d $PATH_SIMU/output_ncrcat || ! -d $PATH_SIMU/output_tar ]] ; then |
---|
65 | `dirname $0`/enlarge_my_files.sh -h |
---|
66 | exit |
---|
67 | fi |
---|
68 | |
---|
69 | #------------------------------------------------------ |
---|
70 | dirin=$1 |
---|
71 | dirout=$2 |
---|
72 | dirout_work=$3 |
---|
73 | |
---|
74 | #------------------------------------------------------ |
---|
75 | function find_varstoexclude { |
---|
76 | nbfile=0 |
---|
77 | for 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 | let nbfile=nbfile+1 |
---|
80 | done |
---|
81 | |
---|
82 | varstoexclude=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if ($1 != nbfile) {print $2}}' | paste -s -d','` |
---|
83 | varstoexcludefiltered=`cat tmp_$$.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if (($1 != nbfile) && !(match($2, /t_inst_(.*)/))) {print $2}}' | paste -s -d','` |
---|
84 | nbvars=`echo $varstoexcludefiltered | gawk -F',' '{print NF}'` |
---|
85 | |
---|
86 | rm -f tmp_$$.txt |
---|
87 | |
---|
88 | return 0 |
---|
89 | } |
---|
90 | |
---|
91 | #------------------------------------------------------ |
---|
92 | for set in $( ls $PATH_SIMU/output_ncrcat/*list ) ; do |
---|
93 | |
---|
94 | #----------------------------------- |
---|
95 | echo "#-------------------" |
---|
96 | echo "Set: $set" |
---|
97 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
98 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
99 | statusfile=${set%%.list}.status |
---|
100 | logfile=${set%%.list}_${datestr}.log |
---|
101 | |
---|
102 | #----------------------------------- |
---|
103 | # Create status file if not exists |
---|
104 | if [ ! -e $statusfile ] ; then |
---|
105 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
106 | fi |
---|
107 | |
---|
108 | #----------------------------------- |
---|
109 | # Switch to tar command |
---|
110 | if [ $switchtotar -eq 1 ] ; then |
---|
111 | echo "====> DELEGATE to tar command with option --switchtotar" |
---|
112 | echo "DELEGATE to tar command with option --switchtotar" >> $statusfile |
---|
113 | mv $set $PATH_SIMU/with_tar |
---|
114 | continue |
---|
115 | fi |
---|
116 | |
---|
117 | #----------------------------------- |
---|
118 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
119 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
120 | printf "====> " |
---|
121 | tail -1 $statusfile |
---|
122 | continue |
---|
123 | fi |
---|
124 | |
---|
125 | #----------------------------------- |
---|
126 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
127 | nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
128 | echo "Nb of tries: $nbtries" |
---|
129 | |
---|
130 | #----------------------------------- |
---|
131 | # Set output file name from first and last files from the current set |
---|
132 | filefirst=`head -n 1 $set` |
---|
133 | fileoutpart1=`basename $filefirst | cut -d'_' -f-2` |
---|
134 | filelast=`tail -n 1 $set` |
---|
135 | fileoutpart2=`basename $filelast | cut -d'_' -f3-` |
---|
136 | |
---|
137 | diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"` |
---|
138 | # outputfile=$diroutputfile/ncrcat_${fileoutpart1}_${fileoutpart2} |
---|
139 | outputfile=$diroutputfile/${fileoutpart1}_${fileoutpart2} |
---|
140 | mkdir -p $diroutputfile |
---|
141 | echo "Output file to write: $outputfile" |
---|
142 | |
---|
143 | #----------------------------------- |
---|
144 | # Find variables to exclude to have homogeneous files (always exclude 't_inst_.*') |
---|
145 | extratar=0 |
---|
146 | find_varstoexclude $set |
---|
147 | if [ $nbvars -eq 0 ] ; then |
---|
148 | varstoexclude="t_inst_.*" |
---|
149 | else |
---|
150 | # There are others variables than 't_inst_.*' so an extra tar file will be created |
---|
151 | varstoexclude="t_inst_.*,$varstoexcludefiltered" |
---|
152 | extratar=1 |
---|
153 | # Copy to with_tar directory |
---|
154 | cp $set $PATH_SIMU/with_tar |
---|
155 | fi |
---|
156 | |
---|
157 | #----------------------------------- |
---|
158 | # Try 2 times before fire "FAILED" |
---|
159 | ncrcatcmd=ncrcat |
---|
160 | ncrcatoptions="--md5_digest" |
---|
161 | # ncrcatoptions="" |
---|
162 | |
---|
163 | cat $set | $ncrcatcmd $ncrcatoptions -O -x -v $varstoexclude -o $outputfile > $logfile 2>&1 |
---|
164 | if [ $? -eq 0 ] ; then |
---|
165 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
166 | echo "DONE ; $datestr1 ; $datestr2 ; cat $set | $ncrcatcmd $ncrcatoptions -O -x -v '$varstoexclude' -o $outputfile ; $logfile ; $extratar" >> $statusfile |
---|
167 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 2)" |
---|
168 | echo "COMPLETED at try #$nbtries (at 1st shot on 2)" >> $statusfile |
---|
169 | else |
---|
170 | # Add --md5_digest |
---|
171 | cat $set | $ncrcatcmd $ncrcatoptions -O -x -v $varstoexclude -o $outputfile > $logfile 2>&1 |
---|
172 | if [ $? -eq 0 ] ; then |
---|
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 2nd shot on 2)" |
---|
176 | echo "COMPLETED at try #$nbtries (at 2nd shot on 2)" >> $statusfile |
---|
177 | else |
---|
178 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
179 | echo "====> FAILED at try #$nbtries" |
---|
180 | echo "FAILED ; $datestr1 ; $datestr2 ; cat $set | $ncrcatcmd $ncrcatoptions -O -x -v '$varstoexclude' -o $outputfile ; $logfile ; $extratar" >> $statusfile |
---|
181 | if [ $nbtries -ge $maxtries ] ; then |
---|
182 | echo "====> DELEGATE to tar command after $nbtries tries (maxtries=$maxtries)" |
---|
183 | echo "DELEGATE to tar command after $nbtries tries (maxtries=$maxtries)" >> $statusfile |
---|
184 | cp $set $PATH_SIMU/with_tar |
---|
185 | fi |
---|
186 | fi |
---|
187 | fi |
---|
188 | |
---|
189 | done |
---|
190 | |
---|
191 | #------------------------------------------------------ |
---|
192 | |
---|
193 | for set in $( ls $PATH_SIMU/output_tar/*list ) ; do |
---|
194 | |
---|
195 | #----------------------------------- |
---|
196 | echo "#-------------------" |
---|
197 | echo "Set: $set" |
---|
198 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
199 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
200 | statusfile=${set%%.list}.status |
---|
201 | logfile=${set%%.list}_${datestr}.log |
---|
202 | |
---|
203 | #----------------------------------- |
---|
204 | # Create status file if not exists |
---|
205 | if [ ! -e $statusfile ] ; then |
---|
206 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
207 | fi |
---|
208 | |
---|
209 | #----------------------------------- |
---|
210 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
211 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
212 | printf "====> " |
---|
213 | tail -1 $statusfile |
---|
214 | continue |
---|
215 | fi |
---|
216 | |
---|
217 | #----------------------------------- |
---|
218 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
219 | # nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
220 | # echo "Nb of tries: $nbtries" |
---|
221 | |
---|
222 | #----------------------------------- |
---|
223 | # Set output file name from list name |
---|
224 | filefirst=`head -n 1 $set` |
---|
225 | dirinputfile=`dirname $filefirst` |
---|
226 | diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"` |
---|
227 | mkdir -p $diroutputfile |
---|
228 | # echo "Output file to write: $outputfile" |
---|
229 | fileout1=$( basename $set ) |
---|
230 | outputfile=${fileout1%.list}.tar |
---|
231 | echo "Output file to write: $outputfile" |
---|
232 | |
---|
233 | #----------------------------------- |
---|
234 | # Try 1 time before fire "FAILED" |
---|
235 | # Waiting for CCRT command |
---|
236 | tarcmd=tar |
---|
237 | taroptions="--format=posix -W -cf" |
---|
238 | |
---|
239 | cd $dirinputfile |
---|
240 | |
---|
241 | set_local=$set".local" |
---|
242 | for file in $( cat $set) ; do |
---|
243 | basename $file >> $set".local" |
---|
244 | done |
---|
245 | |
---|
246 | # #----------------------------------- |
---|
247 | |
---|
248 | $tarcmd $taroptions $diroutputfile/$outputfile --dereference --files-from $set.local > $logfile 2>&1 |
---|
249 | if [ $? -eq 0 ] ; then |
---|
250 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
251 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
252 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
253 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
254 | else |
---|
255 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
256 | echo "====> FAILED at try #$nbtries" |
---|
257 | echo "FAILED ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
258 | |
---|
259 | fi |
---|
260 | rm -f $set".local" |
---|
261 | #----------------------------------- |
---|
262 | |
---|
263 | done |
---|
264 | |
---|
265 | |
---|
266 | #------------------------------------------------------ |
---|
267 | |
---|
268 | for set in $( ls $PATH_SIMU/restart_tar/*list ) ; do |
---|
269 | |
---|
270 | #----------------------------------- |
---|
271 | echo "#-------------------" |
---|
272 | echo "Set: $set" |
---|
273 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
274 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
275 | statusfile=${set%%.list}.status |
---|
276 | logfile=${set%%.list}_${datestr}.log |
---|
277 | |
---|
278 | #----------------------------------- |
---|
279 | # Create status file if not exists |
---|
280 | if [ ! -e $statusfile ] ; then |
---|
281 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
282 | fi |
---|
283 | |
---|
284 | #----------------------------------- |
---|
285 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
286 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
287 | printf "====> " |
---|
288 | tail -1 $statusfile |
---|
289 | continue |
---|
290 | fi |
---|
291 | |
---|
292 | #----------------------------------- |
---|
293 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
294 | # nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
295 | # echo "Nb of tries: $nbtries" |
---|
296 | |
---|
297 | #----------------------------------- |
---|
298 | # Set output file name from list name |
---|
299 | dirin1=$PATH_SIMU/RESTART |
---|
300 | dirin2=${dirin1##${IGCM_DEM}} |
---|
301 | dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )} |
---|
302 | diroutputfile=${OUTPUT_STORE}${dirin3} |
---|
303 | fileout1=$( basename $set ) |
---|
304 | fileout=${fileout1%.list}.tar |
---|
305 | outputfile=$diroutputfile/${fileout} |
---|
306 | mkdir -p $diroutputfile |
---|
307 | echo "Output file to write: $outputfile" |
---|
308 | |
---|
309 | #----------------------------------- |
---|
310 | # Try 1 time before fire "FAILED" |
---|
311 | # Waiting for CCRT command |
---|
312 | tarcmd=tar |
---|
313 | taroptions="--format=posix -W -cf" |
---|
314 | |
---|
315 | cd $dirin1 |
---|
316 | # ls |
---|
317 | |
---|
318 | $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 |
---|
319 | if [ $? -eq 0 ] ; then |
---|
320 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
321 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
322 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
323 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
324 | else |
---|
325 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
326 | echo "====> FAILED at try #$nbtries" |
---|
327 | echo "FAILED ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
328 | |
---|
329 | fi |
---|
330 | |
---|
331 | #----------------------------------- |
---|
332 | |
---|
333 | done |
---|
334 | |
---|
335 | #------------------------------------------------------ |
---|
336 | for set in $( ls $PATH_SIMU/debug_tar/*list ) ; do |
---|
337 | |
---|
338 | #----------------------------------- |
---|
339 | echo "#-------------------" |
---|
340 | echo "Set: $set" |
---|
341 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
342 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
343 | statusfile=${set%%.list}.status |
---|
344 | logfile=${set%%.list}_${datestr}.log |
---|
345 | |
---|
346 | #----------------------------------- |
---|
347 | # Create status file if not exists |
---|
348 | if [ ! -e $statusfile ] ; then |
---|
349 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
350 | fi |
---|
351 | |
---|
352 | #----------------------------------- |
---|
353 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
354 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
355 | printf "====> " |
---|
356 | tail -1 $statusfile |
---|
357 | continue |
---|
358 | fi |
---|
359 | |
---|
360 | #----------------------------------- |
---|
361 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
362 | # nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
363 | # echo "Nb of tries: $nbtries" |
---|
364 | |
---|
365 | #----------------------------------- |
---|
366 | # Set output file name from list name |
---|
367 | dirin1=$PATH_SIMU/DEBUG |
---|
368 | dirin2=${dirin1##${IGCM_DEM}} |
---|
369 | dirin3=${dirin2##/$( basename ${INPUT_DMF_DATA} )} |
---|
370 | diroutputfile=${OUTPUT_STORE}${dirin3} |
---|
371 | fileout1=$( basename $set ) |
---|
372 | fileout=${fileout1%.list}.tar |
---|
373 | outputfile=$diroutputfile/${fileout} |
---|
374 | mkdir -p $diroutputfile |
---|
375 | echo "Output file to write: $outputfile" |
---|
376 | |
---|
377 | #----------------------------------- |
---|
378 | # Try 1 time before fire "FAILED" |
---|
379 | # Waiting for CCRT command |
---|
380 | tarcmd=tar |
---|
381 | taroptions="--format=posix -W -cf" |
---|
382 | |
---|
383 | cd $dirin1 |
---|
384 | # ls |
---|
385 | |
---|
386 | $tarcmd $taroptions $outputfile --dereference --files-from $set > $logfile 2>&1 |
---|
387 | if [ $? -eq 0 ] ; then |
---|
388 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
389 | echo "DONE ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set); $logfile" >> $statusfile |
---|
390 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
391 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
392 | else |
---|
393 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
394 | echo "====> FAILED at try #$nbtries" |
---|
395 | echo "FAILED ; $datestr1 ; $datestr2 ; $tarcmd $taroptions $outputfile $(cat $set) ; $logfile" >> $statusfile |
---|
396 | |
---|
397 | fi |
---|
398 | |
---|
399 | #----------------------------------- |
---|
400 | |
---|
401 | done |
---|
402 | |
---|
403 | #------------------------------------------------------ |
---|
404 | for set in $( ls $PATH_SIMU/store_cp/*list ) ; do |
---|
405 | |
---|
406 | #----------------------------------- |
---|
407 | echo "#-------------------" |
---|
408 | echo "Set: $set" |
---|
409 | datestr=`LC_ALL=C date +"%Y%m%dT%H%M%S"` |
---|
410 | datestr1=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
411 | statusfile=${set%%.list}.status |
---|
412 | logfile=${set%%.list}_${datestr}.log |
---|
413 | |
---|
414 | #----------------------------------- |
---|
415 | # Create status file if not exists |
---|
416 | if [ ! -e $statusfile ] ; then |
---|
417 | echo "# Status ; DateStart ; DateEnd ; Command ; TarFileExists" > $statusfile |
---|
418 | fi |
---|
419 | |
---|
420 | #----------------------------------- |
---|
421 | # Skip the set if last line of the status file is "COMPLETED" or "DELEGATE" |
---|
422 | if tail -1 $statusfile | grep -q -E '(COMPLETED|DELEGATE)' ; then |
---|
423 | printf "====> " |
---|
424 | tail -1 $statusfile |
---|
425 | continue |
---|
426 | fi |
---|
427 | |
---|
428 | #----------------------------------- |
---|
429 | # nbtries = number of lines from status file (first comment line gives 1 for the first try) |
---|
430 | # nbtries=`wc -l $statusfile | cut -d' ' -f1` |
---|
431 | # echo "Nb of tries: $nbtries" |
---|
432 | |
---|
433 | #----------------------------------- |
---|
434 | # Set output file name from first and last files from the current set |
---|
435 | for file in $( cat $set) ; do |
---|
436 | |
---|
437 | diroutputfile=`dirname $file | sed -e "s%$dirin%$dirout%"` |
---|
438 | mkdir -p $diroutputfile |
---|
439 | echo "Output file to write: $diroutputfile/$( basename $file )" |
---|
440 | |
---|
441 | #----------------------------------- |
---|
442 | # Try 1 time before fire "FAILED" |
---|
443 | # Waiting for CCRT command |
---|
444 | cpcmd="cp " |
---|
445 | cpoptions="-rf" |
---|
446 | $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1 |
---|
447 | done |
---|
448 | |
---|
449 | if [ $? -eq 0 ] ; then |
---|
450 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
451 | echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $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 ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
458 | |
---|
459 | fi |
---|
460 | |
---|
461 | #----------------------------------- |
---|
462 | |
---|
463 | done |
---|
464 | |
---|
465 | #------------------------------------------------------ |
---|
466 | for set in $( ls $PATH_SIMU/work_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_work%"` |
---|
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 | $cpcmd $cpoptions $file $diroutputfile > $logfile 2>&1 |
---|
509 | done |
---|
510 | |
---|
511 | if [ $? -eq 0 ] ; then |
---|
512 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
513 | echo "DONE ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
514 | echo "====> COMPLETED at try #$nbtries (at 1st shot on 1)" |
---|
515 | echo "COMPLETED at try #$nbtries (at 1st shot on 1)" >> $statusfile |
---|
516 | else |
---|
517 | datestr2=`LC_ALL=C date +"%Y-%m-%dT%H:%M:%S"` |
---|
518 | echo "====> FAILED at try #$nbtries" |
---|
519 | echo "FAILED ; $datestr1 ; $datestr2 ; $cpcmd $cpoptions $file $diroutputfile ; $logfile" >> $statusfile |
---|
520 | |
---|
521 | fi |
---|
522 | |
---|
523 | #----------------------------------- |
---|
524 | |
---|
525 | done |
---|