1 | #!/bin/sh |
---|
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 | XARGS=/usr/bin/xargs |
---|
12 | SORT=/bin/sort |
---|
13 | RM=/bin/rm |
---|
14 | defaultIFS=$IFS |
---|
15 | |
---|
16 | #set Irods environment |
---|
17 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
18 | |
---|
19 | scriptName="`basename $0`" |
---|
20 | $ECHO "Processing script ${scriptName} at `date`" |
---|
21 | |
---|
22 | #which source to analyse |
---|
23 | sourceRadio=$1 |
---|
24 | |
---|
25 | #Path to public backupable path |
---|
26 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
27 | |
---|
28 | |
---|
29 | #Path where the job will do temporary IO |
---|
30 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then |
---|
31 | iojobpath="/sps/baoradio/AmasNancay/JEC" |
---|
32 | $MKDIR -p $iojobpath |
---|
33 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then |
---|
34 | iojobpath=${TMPBATCH} |
---|
35 | else |
---|
36 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed" |
---|
37 | exit 1 |
---|
38 | fi |
---|
39 | cd ${iojobpath} |
---|
40 | |
---|
41 | localpath="${sourceRadio}" |
---|
42 | $MKDIR -p ./${localpath} |
---|
43 | cd ./${localpath} |
---|
44 | |
---|
45 | |
---|
46 | #Path of the utility scripts |
---|
47 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay" |
---|
48 | |
---|
49 | |
---|
50 | #get the daq current irod status |
---|
51 | tag=`${DATE} +%F` |
---|
52 | OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
53 | |
---|
54 | if [ ! -e ${OUT1} ]; then |
---|
55 | $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
56 | ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
57 | fi |
---|
58 | |
---|
59 | if [ ! "<${sourceRadio}>" = "<>" ]; then |
---|
60 | $ECHO "You have selected sourceRadio = $sourceRadio" |
---|
61 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
62 | else |
---|
63 | tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'` ) |
---|
64 | fi |
---|
65 | IFS=' |
---|
66 | ' |
---|
67 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
68 | |
---|
69 | |
---|
70 | workArea="headers" |
---|
71 | $MKDIR -p ./${workArea} |
---|
72 | cd ./${workArea} |
---|
73 | |
---|
74 | |
---|
75 | nloop4dbg=0 |
---|
76 | |
---|
77 | |
---|
78 | for i in ${tableau[@]} |
---|
79 | do |
---|
80 | #look if the headers have been already extracted |
---|
81 | $ECHO "DEBUG (${scriptName}): irods root dir $i" |
---|
82 | for fibdir in Fiber1 Fiber2; do |
---|
83 | $ECHO "DEBUG (${scriptName}): Fiber $fibdir" |
---|
84 | #NB: care should be taken to the fact that ILS returns all the instance of the file (HPSS, disk...) |
---|
85 | # so one should use a trick to count unique instance |
---|
86 | listOfsig=( `ils ${i}/${fibdir} | $GREP -i "signal" | $XARGS -i basename {} | $SORT -k1.7n` ) |
---|
87 | IFS=' |
---|
88 | ' |
---|
89 | listOfsig=( $( $PRINTF "%s\n" "${listOfsig[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
90 | nblinesSIG=${#listOfsig[@]} |
---|
91 | listOfhdr=( `ils ${i}/${fibdir} | $GREP -i "header" | $XARGS -i basename {} | $SORT -k1.7n` ) |
---|
92 | IFS=' |
---|
93 | ' |
---|
94 | listOfhdr=( $( $PRINTF "%s\n" "${listOfhdr[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
95 | nblinesHDR=${#listOfhdr[@]} |
---|
96 | $ECHO "(DEBUG) (${scriptName}: test if $nblinesHDR != $nblinesSIG " |
---|
97 | if [ $nblinesHDR != $nblinesSIG ]; then |
---|
98 | #do the header extraction |
---|
99 | #build signal files list |
---|
100 | #loop on signal files |
---|
101 | $ECHO "(DEBUG) (${scriptName}): ${listOfsig[@]}" |
---|
102 | |
---|
103 | for sigfname in ${listOfsig[@]} |
---|
104 | do |
---|
105 | filename=$(basename $sigfname) |
---|
106 | extension=${filename##*.} |
---|
107 | filename=${filename%.*} |
---|
108 | number=`$ECHO $filename | $AWK '{len=length("signal");len=len+1;a=substr($1,len);print a}'` |
---|
109 | hdrname="header${number}.txt" |
---|
110 | #look if header file already exists: if so skip it |
---|
111 | hdrIsthere=`ils ${i}/${fibdir}/${hdrname} 2>&1 | $GREP -i "^ERROR" | $WC -l` |
---|
112 | $ECHO "(DEBUG) (${scriptName}): look if ${hdrname} exist (${hdrIsthere})" |
---|
113 | if [ $hdrIsthere -eq 0 ]; then |
---|
114 | continue |
---|
115 | fi |
---|
116 | #get the signal file |
---|
117 | $ECHO "DEBUG (${scriptName}): iget $sigfname (dgg = ${nloop4dbg})" |
---|
118 | OUT3=./igetlog${nloop4dbg}.$$ |
---|
119 | iget -f -v -K ${i}/${fibdir}/${sigfname} . >${OUT3} 2>&1 |
---|
120 | igetStatus=`$GREP "^ERROR" ${OUT3}` |
---|
121 | if [ "<$igetStatus>" != "<>" ]; then |
---|
122 | $ECHO "INFO (${scriptName}): error while iget:" |
---|
123 | $ECHO $igetStatus |
---|
124 | continue |
---|
125 | fi |
---|
126 | $RM $OUT3 |
---|
127 | #extract the header part of the signal file |
---|
128 | $ECHO "DEBUG (${scriptName}): get header from ${sigfname} and put it in ${hdrname}" |
---|
129 | IFS=$defaultIFS |
---|
130 | while read -n80 L |
---|
131 | do |
---|
132 | [ "${L::3}" = "END" ] && break |
---|
133 | $ECHO $L |
---|
134 | done < ${sigfname} > ${hdrname} |
---|
135 | $RM ${sigfname} |
---|
136 | nhdrlines=`$WC -l ${hdrname} | $AWK '{print $1}' ` |
---|
137 | if [ "${nhdrlines}" = "0" ]; then |
---|
138 | $ECHO "WARNING (${scriptName}): ${sigfname} has no valid header" |
---|
139 | else |
---|
140 | #transfert to irod the header |
---|
141 | $ECHO "INFO (${scriptName}): transfert ${hdrname} to ${i}/${fibdir}" |
---|
142 | #use -f option ONLY to force override |
---|
143 | iput -v -K ${hdrname} ${i}/${fibdir} |
---|
144 | fi |
---|
145 | $RM ${hdrname} |
---|
146 | nloop4dbg=$(expr $nloop4dbg + 1) |
---|
147 | done |
---|
148 | else |
---|
149 | $ECHO "INFO (${scriptName}): nothing to do for ${i}/${fibdir}" |
---|
150 | fi |
---|
151 | done |
---|
152 | done |
---|