[507] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
| 3 | #Script sh d'extraction de fichiers d'irod |
---|
| 4 | # Auteur: JE Campagne (LAL Orsay) |
---|
| 5 | # Creation: 2 mai 2011 |
---|
| 6 | # adaptation pour le CC 17 juin 2011 |
---|
| 7 | DATE=/bin/date |
---|
| 8 | GREP=/bin/grep |
---|
| 9 | AWK=/bin/awk |
---|
| 10 | ECHO=/bin/echo |
---|
| 11 | TR=/usr/bin/tr |
---|
| 12 | MKDIR=/bin/mkdir |
---|
| 13 | CAT=/bin/cat |
---|
| 14 | RM=/bin/rm |
---|
| 15 | LS=/bin/ls |
---|
| 16 | DefaultIFS=$' \t\n' |
---|
| 17 | IFS=$DefaultIFS |
---|
| 18 | |
---|
| 19 | scriptName="`basename $0`" |
---|
| 20 | $ECHO "Processing script ${scriptName} at `date`" |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | if [ ! $# = 4 ]; then |
---|
| 25 | $ECHO "usage: ${scriptName} <source:ex. Abell85> <date:YYYYMMDD> first last" |
---|
| 26 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 27 | exit 0 |
---|
| 28 | fi |
---|
| 29 | |
---|
| 30 | # Irods environment settings |
---|
| 31 | #export PATH=$PATH:/home/bao/irods2.5_LinuxSL5 |
---|
| 32 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 33 | |
---|
| 34 | sourceRadio=$1 |
---|
| 35 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 36 | dateDAQ=$2 |
---|
| 37 | |
---|
| 38 | #Path to public backupable path |
---|
| 39 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 40 | |
---|
| 41 | #temporary files to synchronize scripts |
---|
| 42 | tmppublicpath="/sps/baoradio/AmasNancay" |
---|
| 43 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | #Path where the job will do temporary IO |
---|
| 47 | if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then |
---|
| 48 | iojobpath="/sps/baoradio/AmasNancay/JEC" |
---|
| 49 | $MKDIR -p $iojobpath |
---|
| 50 | elif [ ${ENVIRONMENT} == "BATCH" ] ; then |
---|
| 51 | iojobpath=${TMPBATCH} |
---|
| 52 | else |
---|
| 53 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed" |
---|
| 54 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 55 | exit 1 |
---|
| 56 | fi |
---|
| 57 | cd ${iojobpath} |
---|
| 58 | |
---|
| 59 | localpath="${sourceRadio}/${dateDAQ}${srclower}" |
---|
| 60 | $MKDIR -p ./${localpath} |
---|
| 61 | cd ./${localpath} |
---|
| 62 | |
---|
| 63 | #Path of the utility scripts |
---|
[510] | 64 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay" |
---|
[507] | 65 | |
---|
| 66 | |
---|
| 67 | #determine the sequence of signal files to download |
---|
| 68 | #get the daq current irod status |
---|
| 69 | tag=`${DATE} +%F` |
---|
| 70 | OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 71 | |
---|
| 72 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 73 | # $ECHO "We should bring the DAQ status more up to date, this take few |
---|
| 74 | # sec..." |
---|
| 75 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
| 76 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
| 77 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
| 78 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished" |
---|
| 79 | # date +%T |
---|
| 80 | # sleep 30 |
---|
| 81 | # done |
---|
| 82 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
| 83 | $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..." |
---|
| 84 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 85 | exit 1 |
---|
| 86 | fi |
---|
| 87 | |
---|
| 88 | nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` |
---|
| 89 | if [ "<${nfiles}>" == "<>" ]; then |
---|
| 90 | $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>" |
---|
| 91 | $CAT $OUT1 |
---|
| 92 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 93 | exit 1 |
---|
| 94 | fi |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | firstFile=$3 |
---|
| 98 | if [ ${firstFile} -gt ${nfiles} ]; then |
---|
| 99 | $ECHO "FATAL (${scriptName}): ${firstFile} > ${nfiles}" |
---|
| 100 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 101 | exit 1 |
---|
| 102 | fi |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | lastFile=$4 |
---|
| 106 | if [ ${lastFile} -gt ${nfiles} ]; then |
---|
| 107 | $ECHO "FATAL (${scriptName}): ${lastFile} > ${nfiles}" |
---|
| 108 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 109 | exit 1 |
---|
| 110 | fi |
---|
| 111 | |
---|
| 112 | if [ ${firstFile} -gt ${lastFile} ]; then |
---|
| 113 | $ECHO "FATAL (${scriptName}): ${firstFile} > ${lastFile}" |
---|
| 114 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 115 | exit 1 |
---|
| 116 | fi |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}" |
---|
| 120 | dirLocal="." |
---|
| 121 | |
---|
| 122 | ##$ECHO "Ready to download [${firstFile},${lastFile}] in $dirLocal from $dirIrod" |
---|
| 123 | #Nb we are in the localpath |
---|
| 124 | $MKDIR -p Fiber1 |
---|
| 125 | $MKDIR -p Fiber2 |
---|
| 126 | |
---|
| 127 | OUT2=./igetStatus.$$ |
---|
| 128 | |
---|
| 129 | n=$firstFile |
---|
| 130 | while [[ $n -le $lastFile ]]; do |
---|
| 131 | iget -r -f -v -K ${dirIrod}/Fiber1/signal$n.fits ${dirLocal}/Fiber1 >${OUT2} 2>&1 |
---|
| 132 | igetStatus=`$GREP "^ERROR" ${OUT2}` |
---|
| 133 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 134 | $ECHO "FATAL (${scriptName}): error while iget:" |
---|
| 135 | $ECHO $igetStatus |
---|
| 136 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 137 | exit 1 |
---|
| 138 | fi |
---|
| 139 | iget -r -f -v -K ${dirIrod}/Fiber2/signal$n.fits ${dirLocal}/Fiber2 >${OUT2} 2>&1 |
---|
| 140 | igetStatus=`$GREP "^ERROR" ${OUT2}` |
---|
| 141 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 142 | $ECHO "FATAL (${scriptName}): error while iget:" |
---|
| 143 | $ECHO $igetStatus |
---|
| 144 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 145 | exit 1 |
---|
| 146 | fi |
---|
| 147 | n=$(($n+1)) |
---|
| 148 | done |
---|
| 149 | |
---|
| 150 | touch ${tmppublicpath}/getsignalfiles.finished |
---|
| 151 | exit 0 |
---|