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 | user=`whoami`
|
---|
60 | source /home/$user/Mars/datacenter/scripts/sourcefile
|
---|
61 |
|
---|
62 | set -C
|
---|
63 |
|
---|
64 | umask 0002
|
---|
65 |
|
---|
66 | transdir=/home/lapalma/transfer
|
---|
67 | char=28
|
---|
68 | #extern=MAGIC@virgo:/data/MAGIC/transfer
|
---|
69 | datetime=`date +%F-%H-%M-%S`
|
---|
70 |
|
---|
71 | scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
|
---|
72 | if [ ! -d $scriptlogpath ]
|
---|
73 | then
|
---|
74 | mkdir -pv $scriptlogpath
|
---|
75 | if [ ! -d $scriptlogpath ]
|
---|
76 | then
|
---|
77 | echo "could not make scriptlogpath "$scriptlogpath
|
---|
78 | exit
|
---|
79 | fi
|
---|
80 | fi
|
---|
81 |
|
---|
82 | scriptlog=$scriptlogpath/copyscript-$datetime.log
|
---|
83 |
|
---|
84 | date >> $scriptlog 2>&1
|
---|
85 |
|
---|
86 | date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
87 | checklock0=$?
|
---|
88 | case $checklock0 in
|
---|
89 | 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
|
---|
90 | 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
|
---|
91 | echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
|
---|
92 | date >> $scriptlog 2>&1
|
---|
93 | exit;;
|
---|
94 | *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
|
---|
95 | esac
|
---|
96 |
|
---|
97 | # rsync new dc with virgo
|
---|
98 | #rsync -av $extern/ $transdir >> $scriptlog 2>&1
|
---|
99 |
|
---|
100 | cd $transdir
|
---|
101 |
|
---|
102 | #check the checksums, write output into file
|
---|
103 | md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
|
---|
104 | #md5sum -c $transdir/checksums-test >| $transdir/.check
|
---|
105 | if ! test -e $transdir/.check
|
---|
106 | then
|
---|
107 | echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
|
---|
108 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
109 | date >> $scriptlog 2>&1
|
---|
110 | exit
|
---|
111 | else
|
---|
112 | echo "checkfile created" >> $scriptlog 2>&1
|
---|
113 | fi
|
---|
114 |
|
---|
115 | cd $mars
|
---|
116 |
|
---|
117 | echo "remove empty directories: " >> $scriptlog 2>&1
|
---|
118 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
---|
119 |
|
---|
120 | #find all dates in transfer-directory
|
---|
121 | #dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
|
---|
122 | 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
|
---|
123 |
|
---|
124 | if [ "$dates" = "" ]
|
---|
125 | then
|
---|
126 | echo "nothing to do -> exit" >> $scriptlog 2>&1
|
---|
127 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
128 | date >> $scriptlog 2>&1
|
---|
129 | exit
|
---|
130 | fi
|
---|
131 |
|
---|
132 | echo "dates found: "$dates >> $scriptlog 2>&1
|
---|
133 |
|
---|
134 | #loop over dates
|
---|
135 | for date in ${dates[@]}
|
---|
136 | do
|
---|
137 | #find all files for this date
|
---|
138 | files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
|
---|
139 | if [ "$files" = "" ]
|
---|
140 | then
|
---|
141 | echo "no files found for $date" >> $scriptlog 2>&1
|
---|
142 | continue
|
---|
143 | else
|
---|
144 | echo "files found for $date" >> $scriptlog 2>&1
|
---|
145 | fi
|
---|
146 |
|
---|
147 | date2=`echo $date | sed -e 's/_/\//g'`
|
---|
148 | # echo "date2=$date2"
|
---|
149 | copylogpath=$logpath/copyscript/$date2
|
---|
150 | echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
|
---|
151 | if [ ! -d $copylogpath ]
|
---|
152 | then
|
---|
153 | mkdir -pv $copylogpath >> $scriptlog 2>&1
|
---|
154 | if [ ! -d $copylogpath ]
|
---|
155 | then
|
---|
156 | echo "could not make copylogpath $copylogpath -> continue " >> $scriptlog 2>&1
|
---|
157 | continue
|
---|
158 | fi
|
---|
159 | fi
|
---|
160 |
|
---|
161 | #loop over all files in the directories for this date
|
---|
162 | for file in $files
|
---|
163 | do
|
---|
164 | echo "file: "$file >> $scriptlog 2>&1
|
---|
165 | filename=`basename $file`
|
---|
166 | # echo "filename: "$filename
|
---|
167 |
|
---|
168 | #check for each file whether it has to be processed
|
---|
169 | if grep "$filename: OK" $transdir/.check >> $scriptlog 2>&1
|
---|
170 | then
|
---|
171 | newfile=`echo $file | sed -e 's/home\/lapalma\/transfer/magic\/subsystemdata/' -e 's/ccdata/cc/' -e 's/cacodata/caco/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
|
---|
172 | echo "file (new path): "$newfile >> $scriptlog 2>&1
|
---|
173 | newpath=`dirname $newfile`
|
---|
174 | # echo "new path: "$newpath
|
---|
175 | #make sure, that the needed directories are available
|
---|
176 | if [ ! -d $newpath ]
|
---|
177 | then
|
---|
178 | mkdir -pv $newpath >> $scriptlog 2>&1
|
---|
179 | if [ ! -d $newpath ]
|
---|
180 | then
|
---|
181 | echo "could not make path $newpath" >> $scriptlog 2>&1
|
---|
182 | continue
|
---|
183 | fi
|
---|
184 | fi
|
---|
185 |
|
---|
186 | #run macros if the file is a *.rbk or a *.run file to
|
---|
187 | #fill the information into the db
|
---|
188 | if echo $filename | grep .rbk >> $scriptlog 2>&1
|
---|
189 | then
|
---|
190 | echo "found rbk-file $filename" >> $scriptlog 2>&1
|
---|
191 | checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | grep int | sed -e 's/(int)//'`
|
---|
192 | case $checkfillrbk in
|
---|
193 | 1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
|
---|
194 | echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
|
---|
195 | *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
|
---|
196 | continue;;
|
---|
197 | esac
|
---|
198 | fi
|
---|
199 | if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
|
---|
200 | then
|
---|
201 | echo "found run-file $filename" >> $scriptlog 2>&1
|
---|
202 | checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$filename-log.txt | grep int | sed -e 's/(int)//'`
|
---|
203 | case $checkfillrun in
|
---|
204 | 1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
|
---|
205 | echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
|
---|
206 | # date3=`echo $date | sed -e 's/_/-/g'`
|
---|
207 | # echo "date3=$date3"
|
---|
208 | checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | grep int | sed -e 's/(int)//'`
|
---|
209 | case $checkinsertdate in
|
---|
210 | 1) echo "date inserted" >> $scriptlog 2>&1 ;;
|
---|
211 | *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
|
---|
212 | continue;;
|
---|
213 | esac
|
---|
214 | echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
|
---|
215 | *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
|
---|
216 | continue;;
|
---|
217 | esac
|
---|
218 | fi
|
---|
219 |
|
---|
220 | #copy file
|
---|
221 | if mv -v $file $newpath >> $scriptlog 2>&1
|
---|
222 | then
|
---|
223 | #add file to donelist
|
---|
224 | filename3=`echo $file | cut -c $char-999`
|
---|
225 | echo "$filename3 processed" >> $transdir/.processed
|
---|
226 | echo $filename" moved and added to .processed" >> $scriptlog 2>&1
|
---|
227 | else
|
---|
228 | echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
|
---|
229 | fi
|
---|
230 |
|
---|
231 | else
|
---|
232 | #if the checksum for the file is not ok or the file was
|
---|
233 | #already processed (entry in donelist) -> go on with next file
|
---|
234 | echo $file": checksum not ok " >> $scriptlog 2>&1
|
---|
235 | fi
|
---|
236 | done
|
---|
237 | done
|
---|
238 |
|
---|
239 | echo "remove empty directories: " >> $scriptlog 2>&1
|
---|
240 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
---|
241 |
|
---|
242 | rm -v $transdir/.check >> $scriptlog 2>&1
|
---|
243 |
|
---|
244 | #rsync -av $transdir/ $extern >> $scriptlog 2>&1
|
---|
245 | #rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1
|
---|
246 |
|
---|
247 | rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
|
---|
248 | date >> $scriptlog 2>&1
|
---|
249 |
|
---|
250 | set +C
|
---|