source: BAORadio/AmasNancay/trunk/getscafiles.sh @ 575

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

introduce SCRIPTPATH environment variable (jec)

File size: 4.0 KB
Line 
1#!/bin/sh
2#Get SCA file and summary + transformed date file
3#
4DATE=/bin/date
5GREP=/bin/grep
6AWK=/bin/awk
7ECHO=/bin/echo
8TR=/usr/bin/tr
9MKDIR=/bin/mkdir
10CAT=/bin/cat
11PRINTF=/usr/bin/printf
12RM=/bin/rm
13LS=/bin/ls
14DefaultIFS=$' \t\n'
15IFS=$DefaultIFS
16
17scriptName="`basename $0`"
18$ECHO "Processing script ${scriptName} at `date`"
19
20
21if [ ! $# = 2 ]; then
22  $ECHO "usage: ${script
23Name} <source:ex. Abell85> <date:YYYYMMDD>"
24#JEC 29/9/11 avoid finished stuff
25#  touch ${tmppublicpath}/getscafiles.finished
26  exit 0
27fi
28
29# Irods environment settings
30#export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
31. /usr/local/shared/bin/irods_env.sh -noverbose
32
33
34sourceRadio=$1
35srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
36dateDAQ=$2
37
38
39#Path to public backupable path
40publicpath="/afs/in2p3.fr/home/c/campagne/public"
41
42#temporary files to synchronize scripts
43tmppublicpath=${TMPPUBLICPATH}
44$LS -l ${tmppublicpath} > /dev/null
45
46
47#Path where the job will do temporary IO
48if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then
49    iojobpath="/sps/baoradio/AmasNancay/JEC"
50    $MKDIR -p $iojobpath
51elif [ ${ENVIRONMENT} == "BATCH" ] ; then
52 iojobpath=${TMPBATCH}
53else
54   $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
55#JEC 29/9/11 avoid finished stuff
56#   touch ${tmppublicpath}/getscafiles.finished
57   exit 1
58fi
59cd ${iojobpath}
60
61localpath="${sourceRadio}/${dateDAQ}${srclower}"
62$MKDIR -p ./${localpath}
63cd ./${localpath}
64
65
66#Path of the utility scripts
67scriptpath=${SCRIPTPATH}
68
69#JEC 1/10/11 Use generic baodaqstatus name
70#look if the run exists
71#tag=`${DATE} +%F`
72#OUT1=${publicpath}/baodaqstatus-${tag}.txt
73OUT1=${publicpath}/baodaqstatus-current.txt
74
75if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
76#    $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
77#    $RM -f ${tmppublicpath}/statusdaq.finished
78#    ${scriptpath}/statusdaq.sh > ${OUT1}
79#    while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
80#       $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
81#       date +%T
82#       sleep 30
83#     done
84#     $RM ${tmppublicpath}/statusdaq.finished
85    $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
86#JEC 29/9/11 avoid finished stuff
87#    touch ${tmppublicpath}/getscafiles.finished
88    exit 1
89fi
90
91nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` 
92
93if [ "<${nfiles}>" = "<>" ]; then
94    $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
95#JEC 29/9/11 avoid finished stuff
96#    touch ${tmppublicpath}/getscafiles.finished
97    exit 1
98fi
99
100
101#Look if the run should/can be prepared wrt SCA file transformation
102OUT2=./scaStatus.$$
103#JEC 29/9/11 avoid finished stuff
104#$RM -f ${tmppublicpath}/scaextractor.finished
105${scriptpath}/scaextractor.sh $sourceRadio > ${OUT2} 2>&1
106#while [ ! -f "${tmppublicpath}/scaextractor.finished" ]; do
107#    $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/scaextractor.finished"
108#    date +%T
109#    sleep 30
110#done
111#$RM ${tmppublicpath}/scaextractor.finished
112
113
114status=`$GREP "^FATAL.*${sourceRadio}.*${dateDAQ}" ${OUT2}`
115
116if [ "<$status>" != "<>" ]; then
117    $ECHO "FATAL (${scriptName}): connot proceed further with $sourceRadio $dateDAQ"
118#JEC 29/9/11 avoid finished stuff
119#    touch ${tmppublicpath}/getscafiles.finished
120    exit 1
121fi
122$RM $OUT2
123
124#dowload sca files...
125dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
126dirLocal="."
127
128if [ ! -e $dirLocal ]; then
129 $MKDIR -p $dirLocal
130fi
131
132cd $dirLocal
133
134OUT3=./scaFiles.$$
135ils $dirIrod | $GREP -i "sca" > ${OUT3}
136tableau=( `$CAT ${OUT3}`  )
137IFS='
138'
139tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
140IFS=$DefaultIFS
141$RM $OUT3
142
143OUT4=./igetStatus.$$
144for i in ${tableau[@]}
145do
146  if [ ! -e $i ]; then
147    iget -r -f -v -K ${dirIrod}/$i ${dirLocal} > ${OUT4} 2>&1
148  fi
149done
150
151igetStatus=`$GREP "^ERROR" ${OUT4}`
152if [ "<$igetStatus>" != "<>" ]; then
153  $ECHO "FATAL (${scriptName}): error while iget:"
154  $ECHO $igetStatus
155#JEC 29/9/11 avoid finished stuff
156#  touch ${tmppublicpath}/getscafiles.finished
157  exit 1
158fi
159
160$RM -f $OUT4
161
162touch ${tmppublicpath}/getscafiles.finished
163exit 0
Note: See TracBrowser for help on using the repository browser.