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