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
|
---|
13 | DefaultIFS=$' \t\n'
|
---|
14 | IFS=$DefaultIFS
|
---|
15 |
|
---|
16 |
|
---|
17 | #set Irods environment
|
---|
18 | . /usr/local/shared/bin/irods_env.sh -noverbose
|
---|
19 |
|
---|
20 | scriptName="`basename $0`"
|
---|
21 | $ECHO "Processing script ${scriptName} at `date`"
|
---|
22 |
|
---|
23 | #which source to analyse
|
---|
24 | sourceRadio=$1
|
---|
25 |
|
---|
26 | #Path to public backupable path
|
---|
27 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
28 |
|
---|
29 | #temporary files to synchronize scripts
|
---|
30 | tmppublicpath="/sps/baoradio/AmasNancay"
|
---|
31 | $LS -l ${tmppublicpath} > /dev/null
|
---|
32 |
|
---|
33 |
|
---|
34 | #Path where the job will do temporary IO
|
---|
35 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then
|
---|
36 | iojobpath="/sps/baoradio/AmasNancay/JEC"
|
---|
37 | $MKDIR -p $iojobpath
|
---|
38 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then
|
---|
39 | iojobpath=${TMPBATCH}
|
---|
40 | else
|
---|
41 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
|
---|
42 | touch ${tmppublicpath}/scaextractor.finished
|
---|
43 | exit 1
|
---|
44 | fi
|
---|
45 | cd ${iojobpath}
|
---|
46 |
|
---|
47 |
|
---|
48 | localpath="${sourceRadio}"
|
---|
49 | $MKDIR -p ./${localpath}
|
---|
50 | cd ./${localpath}
|
---|
51 |
|
---|
52 |
|
---|
53 | #Path of the utility scripts
|
---|
54 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
|
---|
55 |
|
---|
56 |
|
---|
57 | #get the daq current irod status
|
---|
58 | tag=`${DATE} +%F`
|
---|
59 | OUT1=${publicpath}/baodaqstatus-${tag}.txt
|
---|
60 |
|
---|
61 | if [ ! -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
|
---|
74 | fi
|
---|
75 |
|
---|
76 | if [ ! "<${sourceRadio}>" = "<>" ]; then
|
---|
77 | $ECHO "You have selected sourceRadio = $sourceRadio"
|
---|
78 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
|
---|
79 | else
|
---|
80 | tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` )
|
---|
81 | fi
|
---|
82 | IFS='
|
---|
83 | '
|
---|
84 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
85 | IFS=$DefaultIFS
|
---|
86 |
|
---|
87 | for i in ${tableau[@]}
|
---|
88 | do
|
---|
89 | OUT2=./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}
|
---|
141 | done
|
---|
142 |
|
---|
143 |
|
---|
144 | touch ${tmppublicpath}/scaextractor.finished
|
---|
145 | exit 0
|
---|