source: BAORadio/AmasNancay/trunk/scaextractor.sh @ 579

Last change on this file since 579 was 579, checked in by torrento, 13 years ago

version adaptee a grid engin (ana)

File size: 3.7 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
38. ${SCRIPTPATH}/set_iojobpath.sh
39iojobpath=$(set_iojobpath)
40cd ${iojobpath}
41
42
43localpath="${sourceRadio}"
44$MKDIR -p ./${localpath}
45cd ./${localpath}
46
47
48#Path of the utility scripts
49scriptpath=${SCRIPTPATH}
50
51
52#JEC 1/10/11 Use generic baodaqstatus name
53#get the daq current irod status
54#tag=`${DATE} +%F`
55#OUT1=${publicpath}/baodaqstatus-${tag}.txt
56OUT1=${publicpath}/baodaqstatus-current.txt
57
58
59if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
60    $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
61    exit 1
62fi
63
64if [ ! "<${sourceRadio}>" = "<>" ]; then
65    $ECHO "You have selected sourceRadio = $sourceRadio"
66    tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
67else
68    tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'`  )
69fi
70IFS='
71'
72tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
73IFS=$DefaultIFS
74
75for i in ${tableau[@]}
76do
77OUT2=./baodir.$$
78#scrutinize irods directory
79#Nb: we do not care here if ILS returns non unique instance of a file
80  ils -l $i 2>&1 | $GREP -i "sca" > ${OUT2}
81  $CAT ${OUT2}
82#test if the SCA file has been already processed
83  scatrans=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $NF}'`
84#test if the file is empty due to previous processing dysfunction
85  emptyfile=`$GREP -i "sca.*\.sum\.trans" ${OUT2} | $AWK '{print $4}'`
86#  echo "scrutinize directory <$i>: [$nblines] [$scatrans]"
87  if [ "<${scatrans}>" = "<>" -o "<${emptyfile}>" = "<0>" -o "<${force}>" = "<Yes>" ]; then
88      $ECHO "$i may be non prepared for analysis..."
89      scafile=`$GREP -i "sca[0-9][0-9]*\.[0-9][0-9]*" ${OUT2} | $AWK '{print $NF}'`
90      if [ "<${scafile}>" = "<>" ]; then
91          $ECHO "WARNING (${scriptName}): Cannot download a SCA file for $i"
92      else
93#get sca file
94        iget -r -f -v -K ${i}/${scafile} ${iojobpath}
95#extract summary (sum extension)
96#JEC 29/9/11 avoid finished stuff
97        $RM -f ${tmppublicpath}/sca.finished
98        ${scriptpath}/sca.sh ${scafile}
99#       while [ ! -e "${tmppublicpath}/sca.finished" ]; do
100#           $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/sca.finished"
101#           date +%T
102#           sleep 30
103#       done
104        $ECHO "INFO (${scriptName}): sca.sh has finished"
105#       $RM ${tmppublicpath}/sca.finished
106#TODO see if there is errors...
107        scaFileName=$(basename $scafile)
108        scaFileName=${scaFileName%.*}
109#transform the date (sum.trans extension)
110#JEC 29/9/11 avoid finished stuff
111#       $RM -f ${tmppublicpath}/transdate.finished
112        ${scriptpath}/transdate.sh ${scaFileName}.sum
113#       while [ ! -e "${tmppublicpath}/transdate.finished" ]; do
114#           $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/transdate.finished"
115#           date +%T
116#           sleep 30
117#       done
118        $ECHO "INFO (${scriptName}): transdate.sh  has finished"
119#       $RM ${tmppublicpath}/transdate.finished
120#TODO see if there is errors...
121#put back into Irod
122#       $ECHO "INFO (${scriptName}): where am i: `pwd`"
123#       $LS -lrt
124#       $ECHO "INFO (${scriptName}): see up directory"
125#       $LS -lrt ..
126        iput -f -v -K ${iojobpath}/${scaFileName}.sum $i
127        iput -f -v -K ${iojobpath}/${scaFileName}.sum.trans $i
128      fi
129  fi
130$RM ${OUT2}
131done
132
133exit 0
Note: See TracBrowser for help on using the repository browser.