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

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

version adaptee a grid engin (ana)

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