1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # ========================================================================
|
---|
4 | #
|
---|
5 | # *
|
---|
6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | # * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | # * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | # *
|
---|
11 | # * Permission to use, copy, modify and distribute this software and its
|
---|
12 | # * documentation for any purpose is hereby granted without fee,
|
---|
13 | # * provided that the above copyright notice appear in all copies and
|
---|
14 | # * that both that copyright notice and this permission notice appear
|
---|
15 | # * in supporting documentation. It is provided "as is" without express
|
---|
16 | # * or implied warranty.
|
---|
17 | # *
|
---|
18 | #
|
---|
19 | #
|
---|
20 | # Author(s): Daniela Dorner 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | #
|
---|
28 | # This script handles the subsystem logfiles, which are copied every
|
---|
29 | # day automatically from pc15 in La Palma to /data/MAGIC/transfer/ in
|
---|
30 | # Wuerzburg
|
---|
31 | # The structure in this directory is: subsystem/date/logfile.*
|
---|
32 | # The logfiles are from CC (*.rep, CC*.dbg, CC*.rbk, CC*.rep, CC*.run,
|
---|
33 | # CC*.run.html) and Cosy (cosy*.log, cosy*.rep, tpoint*.txt/starg*.txt)
|
---|
34 | # AMC (AMC*.log, AMC*.info, AMC*.lut) and CaCo (dc*.txt) are not copied
|
---|
35 | # every day automatically
|
---|
36 | #
|
---|
37 | # the script performs the following steps:
|
---|
38 | # ----------------------------------------
|
---|
39 | # - filling the information from the *.rbk and *.run files into the DB
|
---|
40 | # using the macros filldotrbk.C and filldotrun.C
|
---|
41 | # - copying all logfiles to the correct directory:
|
---|
42 | # /Period*/subsystem/date/file.*
|
---|
43 | # (the period for each date is obtained by the macro getperiod.C)
|
---|
44 | # - filling the sequences for the standard analysis into the database
|
---|
45 | # (for each day of which a file was copied)
|
---|
46 | #
|
---|
47 | #
|
---|
48 | # -- to make sure that no file is copied twice there's a textfile
|
---|
49 | # (.processed), to which every file, that was processed, is added
|
---|
50 | # .processed is copied to La Palma, so that it is possible to copy
|
---|
51 | # only new files
|
---|
52 | # -- to make sure that a file was copied completely before it is
|
---|
53 | # processed, a file with the checksum of all files is also copied from
|
---|
54 | # La Palma and the checksum is checked with this script for each file
|
---|
55 | # before processing it.
|
---|
56 | #
|
---|
57 | #
|
---|
58 |
|
---|
59 | export ROOTSYS=/opt/root_v3.10.02
|
---|
60 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
|
---|
61 | export PATH=$PATH:$ROOTSYS/bin
|
---|
62 |
|
---|
63 | set -C
|
---|
64 |
|
---|
65 | mars=/home/operator/Mars
|
---|
66 | macrospath=$mars/datacenter/macros
|
---|
67 | scriptspath=$mars/datacenter/scripts
|
---|
68 | transdir=/magic/datacenter/transfer
|
---|
69 | char=28
|
---|
70 | extern=MAGIC@virgo:/data/MAGIC/transfer
|
---|
71 | datetime=`date +%F-%H-%M-%S`
|
---|
72 |
|
---|
73 | lockpath=/magic/datacenter/locks
|
---|
74 | logpath=/magic/datacenter/autologs
|
---|
75 |
|
---|
76 | scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
|
---|
77 | if [ ! -d $scriptlogpath ]
|
---|
78 | then
|
---|
79 | mkdir -pv $scriptlogpath
|
---|
80 | if [ ! -d $scriptlogpath ]
|
---|
81 | then
|
---|
82 | echo "could not make scriptlogpath "$scriptlogpath
|
---|
83 | exit
|
---|
84 | fi
|
---|
85 | fi
|
---|
86 |
|
---|
87 | scriptlog=$scriptlogpath/copyscript-$datetime.log
|
---|
88 |
|
---|
89 | date >> $scriptlog 2>&1
|
---|
90 |
|
---|
91 | date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
92 | checklock0=$?
|
---|
93 | case $checklock0 in
|
---|
94 | 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
|
---|
95 | 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
|
---|
96 | echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
|
---|
97 | date >> $scriptlog 2>&1
|
---|
98 | exit;;
|
---|
99 | *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
|
---|
100 | esac
|
---|
101 |
|
---|
102 | # rsync new dc with virgo
|
---|
103 | rsync -av $extern/ $transdir >> $scriptlog 2>&1
|
---|
104 |
|
---|
105 | cd $transdir
|
---|
106 |
|
---|
107 | #check the checksums, write output into file
|
---|
108 | md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
|
---|
109 | #md5sum -c $transdir/checksums-test >| $transdir/.check
|
---|
110 | if ! test -e $transdir/.check
|
---|
111 | then
|
---|
112 | echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
|
---|
113 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
114 | date >> $scriptlog 2>&1
|
---|
115 | exit
|
---|
116 | else
|
---|
117 | echo "checkfile created" >> $scriptlog 2>&1
|
---|
118 | fi
|
---|
119 |
|
---|
120 | cd $mars
|
---|
121 |
|
---|
122 | echo "remove empty directories: " >> $scriptlog 2>&1
|
---|
123 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
---|
124 |
|
---|
125 | #find all dates in transfer-directory
|
---|
126 | #dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
|
---|
127 | dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
|
---|
128 |
|
---|
129 | if [ "$dates" = "" ]
|
---|
130 | then
|
---|
131 | echo "nothing to do -> exit" >> $scriptlog 2>&1
|
---|
132 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
133 | date >> $scriptlog 2>&1
|
---|
134 | exit
|
---|
135 | fi
|
---|
136 |
|
---|
137 | echo "dates found: "$dates >> $scriptlog 2>&1
|
---|
138 |
|
---|
139 | #loop over dates
|
---|
140 | for date in ${dates[@]}
|
---|
141 | do
|
---|
142 | #find all files for this date
|
---|
143 | files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
|
---|
144 | if [ "$files" = "" ]
|
---|
145 | then
|
---|
146 | echo "no files found for $date" >> $scriptlog 2>&1
|
---|
147 | continue
|
---|
148 | else
|
---|
149 | echo "files found for $date" >> $scriptlog 2>&1
|
---|
150 | fi
|
---|
151 |
|
---|
152 | date2=`echo $date | sed -e 's/_/\//g'`
|
---|
153 | # echo "date2=$date2"
|
---|
154 | copylogpath=$logpath/copyscript/$date2
|
---|
155 | echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
|
---|
156 | if [ ! -d $copylogpath ]
|
---|
157 | then
|
---|
158 | mkdir -pv $copylogpath >> $scriptlog 2>&1
|
---|
159 | if [ ! -d $copylogpath ]
|
---|
160 | then
|
---|
161 | echo "could not make copylogpath $copylogpath -> continue " >> $scriptlog 2>&1
|
---|
162 | continue
|
---|
163 | fi
|
---|
164 | fi
|
---|
165 |
|
---|
166 | #loop over all files in the directories for this date
|
---|
167 | for file in $files
|
---|
168 | do
|
---|
169 | echo "file: "$file >> $scriptlog 2>&1
|
---|
170 | filename=`basename $file`
|
---|
171 | # echo "filename: "$filename
|
---|
172 |
|
---|
173 | #check for each file whether it has to be processed
|
---|
174 | if grep "$filename: OK" $transdir/.check >> $scriptlog 2>&1
|
---|
175 | then
|
---|
176 | newfile=`echo $file | sed -e 's/datacenter\/transfer/subsystemdata/' -e 's/ccdata/cc/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
|
---|
177 | echo "file (new path): "$newfile >> $scriptlog 2>&1
|
---|
178 | newpath=`dirname $newfile`
|
---|
179 | # echo "new path: "$newpath
|
---|
180 | #make sure, that the needed directories are available
|
---|
181 | if [ ! -d $newpath ]
|
---|
182 | then
|
---|
183 | mkdir -pv $newpath >> $scriptlog 2>&1
|
---|
184 | if [ ! -d $newpath ]
|
---|
185 | then
|
---|
186 | echo "could not make path $newpath" >> $scriptlog 2>&1
|
---|
187 | continue
|
---|
188 | fi
|
---|
189 | fi
|
---|
190 |
|
---|
191 | #run macros if the file is a *.rbk or a *.run file to
|
---|
192 | #fill the information into the db
|
---|
193 | if echo $filename | grep .rbk >> $scriptlog 2>&1
|
---|
194 | then
|
---|
195 | echo "found rbk-file $filename" >> $scriptlog 2>&1
|
---|
196 | checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$date-log.txt | grep int | sed -e 's/(int)//'`
|
---|
197 | case $checkfillrbk in
|
---|
198 | 1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
|
---|
199 | echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
|
---|
200 | *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
|
---|
201 | continue;;
|
---|
202 | esac
|
---|
203 | fi
|
---|
204 | if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
|
---|
205 | then
|
---|
206 | echo "found run-file $filename" >> $scriptlog 2>&1
|
---|
207 | checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$date-log.txt | grep int | sed -e 's/(int)//'`
|
---|
208 | case $checkfillrun in
|
---|
209 | 1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
|
---|
210 | echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
|
---|
211 | # date3=`echo $date | sed -e 's/_/-/g'`
|
---|
212 | # echo "date3=$date3"
|
---|
213 | checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | grep int | sed -e 's/(int)//'`
|
---|
214 | case $checkinsertdate in
|
---|
215 | 1) echo "date inserted" >> $scriptlog 2>&1 ;;
|
---|
216 | *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
|
---|
217 | continue;;
|
---|
218 | esac
|
---|
219 | echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
|
---|
220 | *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
|
---|
221 | continue;;
|
---|
222 | esac
|
---|
223 | fi
|
---|
224 |
|
---|
225 | #copy file
|
---|
226 | if mv -v $file $newpath >> $scriptlog 2>&1
|
---|
227 | then
|
---|
228 | #add file to donelist
|
---|
229 | filename3=`echo $file | cut -c $char-999`
|
---|
230 | echo "$filename3 processed" >> $transdir/.processed
|
---|
231 | echo $filename" moved and added to .processed" >> $scriptlog 2>&1
|
---|
232 | else
|
---|
233 | echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
|
---|
234 | fi
|
---|
235 |
|
---|
236 | else
|
---|
237 | #if the checksum for the file is not ok or the file was
|
---|
238 | #already processed (entry in donelist) -> go on with next file
|
---|
239 | echo $file": checksum not ok " >> $scriptlog 2>&1
|
---|
240 | fi
|
---|
241 | done
|
---|
242 | done
|
---|
243 |
|
---|
244 | echo "remove empty directories: " >> $scriptlog 2>&1
|
---|
245 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
---|
246 |
|
---|
247 | rm -v $transdir/.check >> $scriptlog 2>&1
|
---|
248 |
|
---|
249 | rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1
|
---|
250 |
|
---|
251 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
252 | date >> $scriptlog 2>&1
|
---|
253 |
|
---|
254 | set +C
|
---|