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 | #force recomputation force=Yes |
---|
27 | force=$2 |
---|
28 | |
---|
29 | #Path to public backupable path |
---|
30 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
31 | |
---|
32 | #temporary files to synchronize scripts |
---|
33 | tmppublicpath=${TMPPUBLICPATH} |
---|
34 | $LS -l ${tmppublicpath} > /dev/null |
---|
35 | |
---|
36 | |
---|
37 | #Path where the job will do temporary IO |
---|
38 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
39 | iojobpath=$(set_iojobpath) |
---|
40 | cd ${iojobpath} |
---|
41 | |
---|
42 | |
---|
43 | localpath="${sourceRadio}" |
---|
44 | $MKDIR -p ./${localpath} |
---|
45 | cd ./${localpath} |
---|
46 | |
---|
47 | |
---|
48 | #Path of the utility scripts |
---|
49 | scriptpath=${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 |
---|
56 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
57 | |
---|
58 | |
---|
59 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
60 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
61 | exit 1 |
---|
62 | fi |
---|
63 | |
---|
64 | if [ ! "<${sourceRadio}>" = "<>" ]; then |
---|
65 | $ECHO "You have selected sourceRadio = $sourceRadio" |
---|
66 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
67 | else |
---|
68 | tableau=( `$CAT ${OUT1} | $AWK'( NF==4 ) { print $2 }'` ) |
---|
69 | fi |
---|
70 | IFS=' |
---|
71 | ' |
---|
72 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
73 | IFS=$DefaultIFS |
---|
74 | |
---|
75 | for i in ${tableau[@]} |
---|
76 | do |
---|
77 | OUT2=./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} |
---|
131 | done |
---|
132 | |
---|
133 | exit 0 |
---|