[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 |
|
---|
| 26 | #Path to public backupable path
|
---|
| 27 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
| 28 |
|
---|
| 29 | #temporary files to synchronize scripts
|
---|
[516] | 30 | tmppublicpath=${TMPPUBLICPATH}
|
---|
[507] | 31 | $LS -l ${tmppublicpath} > /dev/null
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | #Path where the job will do temporary IO
|
---|
| 35 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
|
---|
| 36 | iojobpath="/sps/baoradio/AmasNancay/JEC"
|
---|
| 37 | $MKDIR -p $iojobpath
|
---|
| 38 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then
|
---|
| 39 | iojobpath=${TMPBATCH}
|
---|
| 40 | else
|
---|
| 41 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
|
---|
[540] | 42 | #JEC 29/9/11 avoid finished stuff
|
---|
| 43 | # touch ${tmppublicpath}/scaextractor.finished
|
---|
[507] | 44 | exit 1
|
---|
| 45 | fi
|
---|
| 46 | cd ${iojobpath}
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | localpath="${sourceRadio}"
|
---|
| 50 | $MKDIR -p ./${localpath}
|
---|
| 51 | cd ./${localpath}
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | #Path of the utility scripts
|
---|
[510] | 55 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
|
---|
[507] | 56 |
|
---|
| 57 |
|
---|
[540] | 58 | #JEC 1/10/11 Use generic baodaqstatus name
|
---|
[507] | 59 | #get the daq current irod status
|
---|
[540] | 60 | #tag=`${DATE} +%F`
|
---|
| 61 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt
|
---|
| 62 | OUT1=${publicpath}/baodaqstatus-current.txt
|
---|
[507] | 63 |
|
---|
[540] | 64 |
|
---|
[507] | 65 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
|
---|
[540] | 66 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
|
---|
| 67 | exit 1
|
---|
[507] | 68 | # $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
|
---|
| 69 | # $RM -f ${tmppublicpath}/statusdaq.finished
|
---|
| 70 | # ${scriptpath}/statusdaq.sh > ${OUT1}
|
---|
| 71 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
|
---|
| 72 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
|
---|
| 73 | # date +%T
|
---|
| 74 | # sleep 30
|
---|
| 75 | # done
|
---|
| 76 | # $RM ${tmppublicpath}/statusdaq.finished
|
---|
[540] | 77 | # $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
|
---|
| 78 | #JEC 29/9/11 avoid finished stuff
|
---|
| 79 | # touch ${tmppublicpath}/scaextractor.finished
|
---|
| 80 | # exit 1
|
---|
[507] | 81 | fi
|
---|
| 82 |
|
---|
| 83 | if [ ! "<${sourceRadio}>" = "<>" ]; then
|
---|
| 84 | $ECHO "You have selected sourceRadio = $sourceRadio"
|
---|
| 85 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
|
---|
| 86 | else
|
---|
| 87 | tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` )
|
---|
| 88 | fi
|
---|
| 89 | IFS='
|
---|
| 90 | '
|
---|
| 91 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
| 92 | IFS=$DefaultIFS
|
---|
| 93 |
|
---|
| 94 | for i in ${tableau[@]}
|
---|
| 95 | do
|
---|
| 96 | OUT2=./baodir.$$
|
---|
| 97 | #scrutinize irods directory
|
---|
| 98 | #Nb: we do not care here if ILS returns non unique instance of a file
|
---|
| 99 | ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2}
|
---|
| 100 | $CAT ${OUT2}
|
---|
| 101 | #test if the SCA file has been already processed
|
---|
| 102 | scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'`
|
---|
| 103 | #test if the file is empty due to previous processing dysfunction
|
---|
| 104 | emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'`
|
---|
| 105 | # echo "scrutinize directory <$i>: [$nblines] [$scatrans]"
|
---|
| 106 | if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" ]; then
|
---|
| 107 | $ECHO "$i may be non prepared for analysis..."
|
---|
| 108 | scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'`
|
---|
| 109 | if [ "<${scafile}>" = "<>" ]; then
|
---|
| 110 | $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i"
|
---|
| 111 | else
|
---|
| 112 | #get sca file
|
---|
| 113 | iget -r -f -v -K ${i}/${scafile} ${iojobpath}
|
---|
| 114 | #extract summary (sum extension)
|
---|
[540] | 115 | #JEC 29/9/11 avoid finished stuff
|
---|
[507] | 116 | $RM -f ${tmppublicpath}/sca.finished
|
---|
| 117 | ${scriptpath}/sca.sh ${scafile}
|
---|
[540] | 118 | # while [ ! -e "${tmppublicpath}/sca.finished" ]; do
|
---|
| 119 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/sca.finished"
|
---|
| 120 | # date +%T
|
---|
| 121 | # sleep 30
|
---|
| 122 | # done
|
---|
[507] | 123 | $ECHO "INFO (${scriptName}): sca.sh has finished"
|
---|
[540] | 124 | # $RM ${tmppublicpath}/sca.finished
|
---|
[507] | 125 | #TODO see if there is errors...
|
---|
| 126 | scaFileName=$(basename $scafile)
|
---|
| 127 | scaFileName=${scaFileName%.*}
|
---|
| 128 | #transform the date (sum.trans extension)
|
---|
[540] | 129 | #JEC 29/9/11 avoid finished stuff
|
---|
| 130 | # $RM -f ${tmppublicpath}/transdate.finished
|
---|
[507] | 131 | ${scriptpath}/transdate.sh ${scaFileName}.sum
|
---|
[540] | 132 | # while [ ! -e "${tmppublicpath}/transdate.finished" ]; do
|
---|
| 133 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/transdate.finished"
|
---|
| 134 | # date +%T
|
---|
| 135 | # sleep 30
|
---|
| 136 | # done
|
---|
[507] | 137 | $ECHO "INFO (${scriptName}): transdate.sh has finished"
|
---|
[540] | 138 | # $RM ${tmppublicpath}/transdate.finished
|
---|
[507] | 139 | #TODO see if there is errors...
|
---|
| 140 | #put back into Irod
|
---|
| 141 | # $ECHO "INFO (${scriptName}): where am i: `pwd`"
|
---|
| 142 | # $LS -lrt
|
---|
| 143 | # $ECHO "INFO (${scriptName}): see up directory"
|
---|
| 144 | # $LS -lrt ..
|
---|
| 145 | iput -f -v -K ${iojobpath}/${scaFileName}.sum $i
|
---|
| 146 | iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i
|
---|
| 147 | fi
|
---|
| 148 | fi
|
---|
| 149 | $RM ${OUT2}
|
---|
| 150 | done
|
---|
| 151 |
|
---|
| 152 |
|
---|
[540] | 153 | #JEC 29/9/11 avoid finished stuff
|
---|
| 154 | #touch ${tmppublicpath}/scaextractor.finished
|
---|
[507] | 155 | exit 0
|
---|