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