[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 | exit 0 |
---|
| 27 | fi |
---|
| 28 | |
---|
| 29 | # Irods environment settings |
---|
| 30 | #export PATH=$PATH:/home/bao/irods2.5_LinuxSL5 |
---|
| 31 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 32 | |
---|
| 33 | sourceRadio=$1 |
---|
| 34 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 35 | dateDAQ=$2 |
---|
| 36 | |
---|
| 37 | #Path to public backupable path |
---|
| 38 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 39 | |
---|
| 40 | #temporary files to synchronize scripts |
---|
[516] | 41 | tmppublicpath=${TMPPUBLICPATH} |
---|
[507] | 42 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | #Path where the job will do temporary IO |
---|
[579] | 46 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 47 | iojobpath=$(set_iojobpath) |
---|
[507] | 48 | cd ${iojobpath} |
---|
| 49 | |
---|
| 50 | localpath="${sourceRadio}/${dateDAQ}${srclower}" |
---|
| 51 | $MKDIR -p ./${localpath} |
---|
| 52 | cd ./${localpath} |
---|
| 53 | |
---|
| 54 | #Path of the utility scripts |
---|
[575] | 55 | scriptpath=${SCRIPTPATH} |
---|
[507] | 56 | |
---|
| 57 | |
---|
| 58 | #determine the sequence of signal files to download |
---|
[540] | 59 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
[507] | 60 | #get the daq current irod status |
---|
[540] | 61 | #tag=`${DATE} +%F` |
---|
| 62 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 63 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
[507] | 64 | |
---|
| 65 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 66 | # $ECHO "We should bring the DAQ status more up to date, this take few |
---|
| 67 | # sec..." |
---|
| 68 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
| 69 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
| 70 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
| 71 | # $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished" |
---|
| 72 | # date +%T |
---|
| 73 | # sleep 30 |
---|
| 74 | # done |
---|
| 75 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
| 76 | $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..." |
---|
| 77 | exit 1 |
---|
| 78 | fi |
---|
| 79 | |
---|
| 80 | nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` |
---|
| 81 | if [ "<${nfiles}>" == "<>" ]; then |
---|
| 82 | $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>" |
---|
| 83 | $CAT $OUT1 |
---|
| 84 | exit 1 |
---|
| 85 | fi |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | firstFile=$3 |
---|
| 89 | if [ ${firstFile} -gt ${nfiles} ]; then |
---|
| 90 | $ECHO "FATAL (${scriptName}): ${firstFile} > ${nfiles}" |
---|
| 91 | exit 1 |
---|
| 92 | fi |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | lastFile=$4 |
---|
| 96 | if [ ${lastFile} -gt ${nfiles} ]; then |
---|
| 97 | $ECHO "FATAL (${scriptName}): ${lastFile} > ${nfiles}" |
---|
| 98 | exit 1 |
---|
| 99 | fi |
---|
| 100 | |
---|
| 101 | if [ ${firstFile} -gt ${lastFile} ]; then |
---|
| 102 | $ECHO "FATAL (${scriptName}): ${firstFile} > ${lastFile}" |
---|
| 103 | exit 1 |
---|
| 104 | fi |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}" |
---|
| 108 | dirLocal="." |
---|
| 109 | |
---|
| 110 | ##$ECHO "Ready to download [${firstFile},${lastFile}] in $dirLocal from $dirIrod" |
---|
| 111 | #Nb we are in the localpath |
---|
| 112 | $MKDIR -p Fiber1 |
---|
| 113 | $MKDIR -p Fiber2 |
---|
| 114 | |
---|
| 115 | OUT2=./igetStatus.$$ |
---|
| 116 | |
---|
| 117 | n=$firstFile |
---|
| 118 | while [[ $n -le $lastFile ]]; do |
---|
| 119 | iget -r -f -v -K ${dirIrod}/Fiber1/signal$n.fits ${dirLocal}/Fiber1 >${OUT2} 2>&1 |
---|
| 120 | igetStatus=`$GREP "^ERROR" ${OUT2}` |
---|
| 121 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 122 | $ECHO "FATAL (${scriptName}): error while iget:" |
---|
| 123 | $ECHO $igetStatus |
---|
| 124 | exit 1 |
---|
| 125 | fi |
---|
| 126 | iget -r -f -v -K ${dirIrod}/Fiber2/signal$n.fits ${dirLocal}/Fiber2 >${OUT2} 2>&1 |
---|
| 127 | igetStatus=`$GREP "^ERROR" ${OUT2}` |
---|
| 128 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 129 | $ECHO "FATAL (${scriptName}): error while iget:" |
---|
| 130 | $ECHO $igetStatus |
---|
| 131 | exit 1 |
---|
| 132 | fi |
---|
| 133 | n=$(($n+1)) |
---|
| 134 | done |
---|
| 135 | |
---|
| 136 | exit 0 |
---|