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