[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 |
---|
[626] | 13 | TR=/usr/bin/tr |
---|
[507] | 14 | DefaultIFS=$' \t\n' |
---|
| 15 | IFS=$DefaultIFS |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #set Irods environment |
---|
| 19 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 20 | |
---|
| 21 | scriptName="`basename $0`" |
---|
| 22 | $ECHO "Processing script ${scriptName} at `date`" |
---|
| 23 | |
---|
[626] | 24 | #Process cmd line args: the -src option is mandatory (source name as Abell85) |
---|
| 25 | sourceRadio= |
---|
| 26 | dateSelected= |
---|
| 27 | #force recomputation force=Yes |
---|
| 28 | force="No" |
---|
| 29 | #use Drift Scan script=Yes |
---|
| 30 | is4DriftScan="No" |
---|
| 31 | while [ $# -gt 0 ] |
---|
| 32 | do |
---|
| 33 | case "$1" in |
---|
| 34 | -src) sourceRadio=$2; shift;; |
---|
| 35 | -date) dateSelected=$2; shift;; |
---|
[627] | 36 | -force) force="Yes";; |
---|
| 37 | -drift) is4DriftScan="Yes";; |
---|
[626] | 38 | -h) |
---|
| 39 | echo >&2 \ |
---|
| 40 | "usage: $0 -src souce -date YYYYMMDD [-force] [-drift]" |
---|
| 41 | exit 1;; |
---|
| 42 | *) break;; # terminate while loop |
---|
| 43 | esac |
---|
| 44 | shift |
---|
| 45 | done |
---|
| 46 | |
---|
| 47 | |
---|
[507] | 48 | #which source to analyse |
---|
[626] | 49 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
[507] | 50 | |
---|
[576] | 51 | |
---|
[507] | 52 | #Path to public backupable path |
---|
| 53 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 54 | |
---|
| 55 | #temporary files to synchronize scripts |
---|
[516] | 56 | tmppublicpath=${TMPPUBLICPATH} |
---|
[507] | 57 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | #Path where the job will do temporary IO |
---|
[579] | 61 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 62 | iojobpath=$(set_iojobpath) |
---|
[507] | 63 | cd ${iojobpath} |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | localpath="${sourceRadio}" |
---|
| 67 | $MKDIR -p ./${localpath} |
---|
| 68 | cd ./${localpath} |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | #Path of the utility scripts |
---|
[575] | 72 | scriptpath=${SCRIPTPATH} |
---|
[507] | 73 | |
---|
| 74 | |
---|
[540] | 75 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
| 76 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
[507] | 77 | |
---|
[540] | 78 | |
---|
[507] | 79 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
[540] | 80 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 81 | exit 1 |
---|
[507] | 82 | fi |
---|
| 83 | |
---|
| 84 | if [ ! "<${sourceRadio}>" = "<>" ]; then |
---|
[626] | 85 | $ECHO "You have selected sourceRadio = $sourceRadio[date = ${dateSelected}]" |
---|
| 86 | #JEC 14/12/11 One should take care of DR extension for Drift Scan |
---|
| 87 | #tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 88 | tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
[507] | 89 | else |
---|
| 90 | tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` ) |
---|
| 91 | fi |
---|
| 92 | IFS=' |
---|
| 93 | ' |
---|
| 94 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 95 | IFS=$DefaultIFS |
---|
| 96 | |
---|
| 97 | for i in ${tableau[@]} |
---|
| 98 | do |
---|
| 99 | OUT2=./baodir.$$ |
---|
| 100 | #scrutinize irods directory |
---|
| 101 | #Nb: we do not care here if ILS returns non unique instance of a file |
---|
| 102 | ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2} |
---|
| 103 | $CAT ${OUT2} |
---|
| 104 | #test if the SCA file has been already processed |
---|
| 105 | scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'` |
---|
| 106 | #test if the file is empty due to previous processing dysfunction |
---|
| 107 | emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'` |
---|
| 108 | # echo "scrutinize directory <$i>: [$nblines] [$scatrans]" |
---|
[576] | 109 | if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" -o "<${force}>" = "<Yes>" ]; then |
---|
[507] | 110 | $ECHO "$i may be non prepared for analysis..." |
---|
| 111 | scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'` |
---|
| 112 | if [ "<${scafile}>" = "<>" ]; then |
---|
| 113 | $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i" |
---|
| 114 | else |
---|
| 115 | #get sca file |
---|
| 116 | iget -r -f -v -K ${i}/${scafile} ${iojobpath} |
---|
| 117 | #extract summary (sum extension) |
---|
[626] | 118 | #JEC 7/12/11 START |
---|
| 119 | if [ "<${is4DriftScan}>" != "<Yes>" ]; then |
---|
| 120 | ${scriptpath}/sca.sh ${scafile} |
---|
| 121 | $ECHO "INFO (${scriptName}): sca.sh has finished" |
---|
| 122 | else |
---|
| 123 | ${scriptpath}/sca_ds.sh ${scafile} |
---|
| 124 | $ECHO "INFO (${scriptName}): sca_ds.sh has finished" |
---|
| 125 | fi |
---|
| 126 | # |
---|
[507] | 127 | #TODO see if there is errors... |
---|
| 128 | scaFileName=$(basename $scafile) |
---|
| 129 | scaFileName=${scaFileName%.*} |
---|
| 130 | #transform the date (sum.trans extension) |
---|
| 131 | ${scriptpath}/transdate.sh ${scaFileName}.sum |
---|
| 132 | $ECHO "INFO (${scriptName}): transdate.sh has finished" |
---|
| 133 | iput -f -v -K ${iojobpath}/${scaFileName}.sum $i |
---|
| 134 | iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i |
---|
| 135 | fi |
---|
| 136 | fi |
---|
| 137 | $RM ${OUT2} |
---|
| 138 | done |
---|
| 139 | |
---|
| 140 | exit 0 |
---|