source: BAORadio/AmasNancay/v4/scaextractor.sh @ 617

Last change on this file since 617 was 576, checked in by campagne, 13 years ago

u_irods_baoradio pour BQS (jec)

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