source: BAORadio/AmasNancay/getscafiles.sh @ 510

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

change scriptpath (general) + minor things

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