[507] | 1 | #!/bin/sh -xvf |
---|
| 2 | #download SCA file, proceed to introspection, and upload results |
---|
| 3 | DATE=/bin/date |
---|
| 4 | GREP=/bin/grep |
---|
| 5 | AWK=/bin/awk |
---|
| 6 | ECHO=/bin/echo |
---|
| 7 | WC=/usr/bin/wc |
---|
| 8 | CAT=/bin/cat |
---|
| 9 | PRINTF=/usr/bin/printf |
---|
| 10 | MKDIR=/bin/mkdir |
---|
| 11 | RM=/bin/rm |
---|
| 12 | LS=/bin/ls |
---|
| 13 | DefaultIFS=$' \t\n' |
---|
| 14 | IFS=$DefaultIFS |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | #set Irods environment |
---|
| 18 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 19 | |
---|
| 20 | scriptName="`basename $0`" |
---|
| 21 | $ECHO "Processing script ${scriptName} at `date`" |
---|
| 22 | |
---|
| 23 | #which source to analyse |
---|
| 24 | sourceRadio=$1 |
---|
| 25 | |
---|
[576] | 26 | #force recomputation force=Yes |
---|
| 27 | force=$2 |
---|
| 28 | |
---|
[507] | 29 | #Path to public backupable path |
---|
| 30 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 31 | |
---|
| 32 | #temporary files to synchronize scripts |
---|
[516] | 33 | tmppublicpath=${TMPPUBLICPATH} |
---|
[507] | 34 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | #Path where the job will do temporary IO |
---|
[579] | 38 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 39 | iojobpath=$(set_iojobpath) |
---|
[507] | 40 | cd ${iojobpath} |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | localpath="${sourceRadio}" |
---|
| 44 | $MKDIR -p ./${localpath} |
---|
| 45 | cd ./${localpath} |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | #Path of the utility scripts |
---|
[575] | 49 | scriptpath=${SCRIPTPATH} |
---|
[507] | 50 | |
---|
| 51 | |
---|
[540] | 52 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
[507] | 53 | #get the daq current irod status |
---|
[540] | 54 | #tag=`${DATE} +%F` |
---|
| 55 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 56 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
[507] | 57 | |
---|
[540] | 58 | |
---|
[507] | 59 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
[540] | 60 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 61 | exit 1 |
---|
[507] | 62 | fi |
---|
| 63 | |
---|
| 64 | if [ ! "<${sourceRadio}>" = "<>" ]; then |
---|
| 65 | $ECHO "You have selected sourceRadio = $sourceRadio" |
---|
| 66 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 67 | else |
---|
| 68 | tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` ) |
---|
| 69 | fi |
---|
| 70 | IFS=' |
---|
| 71 | ' |
---|
| 72 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 73 | IFS=$DefaultIFS |
---|
| 74 | |
---|
| 75 | for i in ${tableau[@]} |
---|
| 76 | do |
---|
| 77 | OUT2=./baodir.$$ |
---|
| 78 | #scrutinize irods directory |
---|
| 79 | #Nb: we do not care here if ILS returns non unique instance of a file |
---|
| 80 | ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2} |
---|
| 81 | $CAT ${OUT2} |
---|
| 82 | #test if the SCA file has been already processed |
---|
| 83 | scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'` |
---|
| 84 | #test if the file is empty due to previous processing dysfunction |
---|
| 85 | emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'` |
---|
| 86 | # echo "scrutinize directory <$i>: [$nblines] [$scatrans]" |
---|
[576] | 87 | if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" -o "<${force}>" = "<Yes>" ]; then |
---|
[507] | 88 | $ECHO "$i may be non prepared for analysis..." |
---|
| 89 | scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'` |
---|
| 90 | if [ "<${scafile}>" = "<>" ]; then |
---|
| 91 | $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i" |
---|
| 92 | else |
---|
| 93 | #get sca file |
---|
| 94 | iget -r -f -v -K ${i}/${scafile} ${iojobpath} |
---|
| 95 | #extract summary (sum extension) |
---|
[540] | 96 | #JEC 29/9/11 avoid finished stuff |
---|
[507] | 97 | $RM -f ${tmppublicpath}/sca.finished |
---|
| 98 | ${scriptpath}/sca.sh ${scafile} |
---|
[540] | 99 | # while [ ! -e "${tmppublicpath}/sca.finished" ]; do |
---|
| 100 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/sca.finished" |
---|
| 101 | # date +%T |
---|
| 102 | # sleep 30 |
---|
| 103 | # done |
---|
[507] | 104 | $ECHO "INFO (${scriptName}): sca.sh has finished" |
---|
[540] | 105 | # $RM ${tmppublicpath}/sca.finished |
---|
[507] | 106 | #TODO see if there is errors... |
---|
| 107 | scaFileName=$(basename $scafile) |
---|
| 108 | scaFileName=${scaFileName%.*} |
---|
| 109 | #transform the date (sum.trans extension) |
---|
[540] | 110 | #JEC 29/9/11 avoid finished stuff |
---|
| 111 | # $RM -f ${tmppublicpath}/transdate.finished |
---|
[507] | 112 | ${scriptpath}/transdate.sh ${scaFileName}.sum |
---|
[540] | 113 | # while [ ! -e "${tmppublicpath}/transdate.finished" ]; do |
---|
| 114 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/transdate.finished" |
---|
| 115 | # date +%T |
---|
| 116 | # sleep 30 |
---|
| 117 | # done |
---|
[507] | 118 | $ECHO "INFO (${scriptName}): transdate.sh has finished" |
---|
[540] | 119 | # $RM ${tmppublicpath}/transdate.finished |
---|
[507] | 120 | #TODO see if there is errors... |
---|
| 121 | #put back into Irod |
---|
| 122 | # $ECHO "INFO (${scriptName}): where am i: `pwd`" |
---|
| 123 | # $LS -lrt |
---|
| 124 | # $ECHO "INFO (${scriptName}): see up directory" |
---|
| 125 | # $LS -lrt .. |
---|
| 126 | iput -f -v -K ${iojobpath}/${scaFileName}.sum $i |
---|
| 127 | iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i |
---|
| 128 | fi |
---|
| 129 | fi |
---|
| 130 | $RM ${OUT2} |
---|
| 131 | done |
---|
| 132 | |
---|
| 133 | exit 0 |
---|