source: BAORadio/AmasNancay/scaextractor.sh @ 510

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

change scriptpath (general) + minor things

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