| 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-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | #
|
|---|
| 28 | # This script handles the subsystem logfiles, which are copied every
|
|---|
| 29 | # day automatically from /local/ on pc15 in La Palma to
|
|---|
| 30 | # /home/lapalma/transfer/ on coma in the datacenter in 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), Cosy (cosy*.log, cosy*.rep, tpoint*.txt/starg*.txt)
|
|---|
| 34 | # AMC (AMC*.log, AMC*.info, AMC*.lut) and CaCo (dc*.txt)
|
|---|
| 35 | #
|
|---|
| 36 | # the script performs the following steps:
|
|---|
| 37 | # ----------------------------------------
|
|---|
| 38 | # - filling the information from the *.rbk and *.run files into the DB
|
|---|
| 39 | # using the macros filldotrbk.C and filldotrun.C
|
|---|
| 40 | # - moving all logfiles to the correct directory:
|
|---|
| 41 | # /subsystemdata/subsystem/YYYY/MM/DD/file.*
|
|---|
| 42 | # - building the sequences for the standard analysis in the database
|
|---|
| 43 | # (for each day of which a file was copied)
|
|---|
| 44 | # - if a new catalogfile has been copied, it is installed as standard in the
|
|---|
| 45 | # setup directory /magic/datacenter/setup and the new lines are sent to
|
|---|
| 46 | # the adresses specified in the script
|
|---|
| 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 | source `dirname $0`/sourcefile
|
|---|
| 60 | printprocesslog "INFO starting $0"
|
|---|
| 61 | program=copyscript
|
|---|
| 62 |
|
|---|
| 63 | set -C
|
|---|
| 64 |
|
|---|
| 65 | umask 0002
|
|---|
| 66 |
|
|---|
| 67 | transdir=/home/lapalma/transfer
|
|---|
| 68 | char=24
|
|---|
| 69 | datetime=`date +%F-%H-%M-%S`
|
|---|
| 70 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 71 |
|
|---|
| 72 | scriptlog=$runlogpath/$program-$datetime.log
|
|---|
| 73 | date >> $scriptlog 2>&1
|
|---|
| 74 |
|
|---|
| 75 | # check if the script is already running
|
|---|
| 76 | checklock >> $scriptlog 2>&1
|
|---|
| 77 |
|
|---|
| 78 | cd $transdir
|
|---|
| 79 |
|
|---|
| 80 | #check the checksums, write output into file
|
|---|
| 81 | md5sum -c .checksums | tee $transdir/.check >> $scriptlog 2>&1
|
|---|
| 82 |
|
|---|
| 83 | if ! test -e $transdir/.check
|
|---|
| 84 | then
|
|---|
| 85 | echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
|
|---|
| 86 | finish >> $scriptlog 2>&1
|
|---|
| 87 | else
|
|---|
| 88 | echo "checkfile created" >> $scriptlog 2>&1
|
|---|
| 89 | fi
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | ssh lapalma@dc09 chmod -R g+w $transdir/* >> $scriptlog 2>&1
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | cd $mars
|
|---|
| 96 |
|
|---|
| 97 | echo "remove empty directories: " >> $scriptlog 2>&1
|
|---|
| 98 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
|---|
| 99 |
|
|---|
| 100 | #find all dates in transfer-directory
|
|---|
| 101 | dates=`find $transdir/*/ -type d | grep -o --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | sort | uniq` >> $scriptlog 2>&1
|
|---|
| 102 | if ! [ "$dates" = "" ]
|
|---|
| 103 | then
|
|---|
| 104 | echo "dates found: "$dates >> $scriptlog 2>&1
|
|---|
| 105 | #loop over dates
|
|---|
| 106 | for date in ${dates[@]}
|
|---|
| 107 | do
|
|---|
| 108 | printprocesslog "INFO processing files for $date"
|
|---|
| 109 | #find all files for this date
|
|---|
| 110 | files=`find $transdir/*/$date/ -name "*.*"` >> $scriptlog 2>&1
|
|---|
| 111 | if [ "$files" = "" ]
|
|---|
| 112 | then
|
|---|
| 113 | echo "no files found for $date" >> $scriptlog 2>&1
|
|---|
| 114 | continue
|
|---|
| 115 | else
|
|---|
| 116 | echo "files found for $date" >> $scriptlog 2>&1
|
|---|
| 117 | fi
|
|---|
| 118 |
|
|---|
| 119 | date2=`echo $date | sed -e 's/_/\//g'`
|
|---|
| 120 | copylogpath=$logpath/$program/$date2
|
|---|
| 121 | echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
|
|---|
| 122 | makedir $copylogpath >> $scriptlog 2>&1
|
|---|
| 123 |
|
|---|
| 124 | #loop over all files in the directories for this date
|
|---|
| 125 | for file in $files
|
|---|
| 126 | do
|
|---|
| 127 | echo "file: "$file >> $scriptlog 2>&1
|
|---|
| 128 | filename=`basename $file`
|
|---|
| 129 |
|
|---|
| 130 | #check for each file whether it has to be processed
|
|---|
| 131 | if grep -i "$filename: OK" $transdir/.check >> $scriptlog 2>&1
|
|---|
| 132 | then
|
|---|
| 133 | 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' `
|
|---|
| 134 | echo "file (new path): "$newfile >> $scriptlog 2>&1
|
|---|
| 135 | newpath=`dirname $newfile`
|
|---|
| 136 | #make sure, that the needed directories are available
|
|---|
| 137 | makedir $newpath >> $scriptlog 2>&1
|
|---|
| 138 |
|
|---|
| 139 | #run macros if the file is a *.rbk or a *.run file to
|
|---|
| 140 | #fill the information into the db
|
|---|
| 141 | if echo $filename | grep \\\.rbk$ >> $scriptlog 2>&1
|
|---|
| 142 | then
|
|---|
| 143 | echo "found rbk-file $filename" >> $scriptlog 2>&1
|
|---|
| 144 |
|
|---|
| 145 | checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$filename-log.txt | intgrep`
|
|---|
| 146 |
|
|---|
| 147 | case $checkfillrbk in
|
|---|
| 148 | 1) echo " checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1
|
|---|
| 149 | echo " -> go on with moving file" >> $scriptlog 2>&1
|
|---|
| 150 | ;;
|
|---|
| 151 | *) echo " checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1
|
|---|
| 152 | printprocesslog "ERROR filldotrbk.C failed for $file"
|
|---|
| 153 | continue
|
|---|
| 154 | ;;
|
|---|
| 155 | esac
|
|---|
| 156 | fi
|
|---|
| 157 |
|
|---|
| 158 | if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1 && ! echo $file | grep .run.html >> $scriptlog 2>&1
|
|---|
| 159 | then
|
|---|
| 160 | echo "found run-file $filename" >> $scriptlog 2>&1
|
|---|
| 161 |
|
|---|
| 162 | fillrunlog=$copylogpath"/filldotrun-$filename-log.txt"
|
|---|
| 163 | checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $fillrunlog | intgrep`
|
|---|
| 164 | if grep WARN $fillrunlog >/dev/null
|
|---|
| 165 | then
|
|---|
| 166 | printprocesslog "WARN found in logfile "$fillrunlog
|
|---|
| 167 | fi
|
|---|
| 168 |
|
|---|
| 169 | if grep ERROR $fillrunlog >/dev/null
|
|---|
| 170 | then
|
|---|
| 171 | printprocesslog "ERROR found in logfile "$fillrunlog
|
|---|
| 172 | fi
|
|---|
| 173 |
|
|---|
| 174 | case $checkfillrun in
|
|---|
| 175 | 1) echo " checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1
|
|---|
| 176 | echo " -> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1
|
|---|
| 177 |
|
|---|
| 178 | checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt | intgrep`
|
|---|
| 179 |
|
|---|
| 180 | case $checkinsertdate in
|
|---|
| 181 | 1) echo "date inserted" >> $scriptlog 2>&1 ;;
|
|---|
| 182 | *) echo " checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1
|
|---|
| 183 | printprocesslog "ERROR insertdate.C failed for $date"
|
|---|
| 184 | continue
|
|---|
| 185 | ;;
|
|---|
| 186 | esac
|
|---|
| 187 | echo " -> go on with moving file" >> $scriptlog 2>&1
|
|---|
| 188 | ;;
|
|---|
| 189 | *) echo " checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1
|
|---|
| 190 | printprocesslog "ERROR filldotrun.C failed for $file"
|
|---|
| 191 | continue
|
|---|
| 192 | ;;
|
|---|
| 193 | esac
|
|---|
| 194 | fi
|
|---|
| 195 |
|
|---|
| 196 | if mv -v $file $newpath >> $scriptlog 2>&1
|
|---|
| 197 | then
|
|---|
| 198 | #add file to donelist
|
|---|
| 199 | filename3=`echo $file | cut -c $char-999`
|
|---|
| 200 | echo "$filename3 processed" >> $transdir/.processed
|
|---|
| 201 | echo $filename" moved and added to .processed" >> $scriptlog 2>&1
|
|---|
| 202 | else
|
|---|
| 203 | echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1
|
|---|
| 204 | printprocesslog "WARN moving of file $file didn't work"
|
|---|
| 205 | fi
|
|---|
| 206 |
|
|---|
| 207 | else
|
|---|
| 208 | #if the checksum for the file is not ok or the file was
|
|---|
| 209 | #already processed (entry in donelist) -> go on with next file
|
|---|
| 210 | echo $file": checksum not ok " >> $scriptlog 2>&1
|
|---|
| 211 | printprocesslog "WARN checksum for file $file is not ok"
|
|---|
| 212 | fi
|
|---|
| 213 | done
|
|---|
| 214 | done
|
|---|
| 215 | fi
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 | echo "remove empty directories: " >> $scriptlog 2>&1
|
|---|
| 219 | rmdir -pv $transdir/*/* >> $scriptlog 2>&1
|
|---|
| 220 |
|
|---|
| 221 | rm -v $transdir/.check >> $scriptlog 2>&1
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 | # second part of the script
|
|---|
| 225 | #searching optical data files, inserting the information into the db and
|
|---|
| 226 | #moving the files
|
|---|
| 227 | file=""
|
|---|
| 228 | printprocesslog "INFO processing optical files"
|
|---|
| 229 | echo "processing optical files..." >> $scriptlog 2>&1
|
|---|
| 230 | opticalfiles=`find $transdir/optical -regextype posix-egrep -regex "^$transdir/optical/20[0-9][0-9]_[0-1][0-9]_[0-3][0-9]_.*_[RV][_]?[12]?[.]instr$"`
|
|---|
| 231 | for opticalfile in $opticalfiles
|
|---|
| 232 | do
|
|---|
| 233 | printprocesslog "INFO process "$opticalfile
|
|---|
| 234 | file=`basename $opticalfile`
|
|---|
| 235 | year=`echo $file | cut -c 0-4`
|
|---|
| 236 | opticallogpath=$logpath/filloptical/$year
|
|---|
| 237 | makedir $opticallogpath >> $scriptlog 2>&1
|
|---|
| 238 | opticallogfile=$opticallogpath/filloptical-$file.log
|
|---|
| 239 |
|
|---|
| 240 | checkfilloptical=`root -q -b $macrospath/filloptical.C+\("\"$opticalfile\""\,kFALSE\) | tee $opticallogfile | intgrep`
|
|---|
| 241 |
|
|---|
| 242 | case $checkfilloptical in
|
|---|
| 243 | 1) echo " checkfilloptical=$checkfilloptical -> everything ok -> go on with moving file" >> $scriptlog 2>&1
|
|---|
| 244 | newdir=$subsystempath/optical/$year
|
|---|
| 245 | newfile=$newdir/$file
|
|---|
| 246 | makedir $newdir >> $scriptlog 2>&1
|
|---|
| 247 |
|
|---|
| 248 | if mv -v $opticalfile $newfile >> $scriptlog 2>&1
|
|---|
| 249 | then
|
|---|
| 250 | echo "moved "$opticalfile" successfully" >> $scriptlog 2>&1
|
|---|
| 251 | printprocesslog "INFO moved "$opticalfile" successfully"
|
|---|
| 252 | else
|
|---|
| 253 | echo $opticalfile" couldn't be moved!!!!!" >> $scriptlog 2>&1
|
|---|
| 254 | printprocesslog "WARN moving of file $opticalfile didn't work"
|
|---|
| 255 | fi
|
|---|
| 256 | ;;
|
|---|
| 257 | 3) echo " checkfilloptical=$checkfilloptical - ERROR filloptical.C failed for $opticalfile: position of one object is missing in the database" >> $scriptlog 2>&1
|
|---|
| 258 | printprocesslog "ERROR filloptical.C failed for $opticalfile: position of one object is missing in the database"
|
|---|
| 259 | continue ;;
|
|---|
| 260 | 4) echo " checkfilloptical=$checkfilloptical - ERROR filloptical.C failed for $opticalfile: telescope line with more or less than 2 arguments" >> $scriptlog 2>&1
|
|---|
| 261 | printprocesslog "ERROR filloptical.C failed for $opticalfile: telescope line with more or less than 2 arguments"
|
|---|
| 262 | continue ;;
|
|---|
| 263 | 5) echo " checkfilloptical=$checkfilloptical - ERROR filloptical.C failed for $opticalfile: timestamp line with more or less than 4 arguments" >> $scriptlog 2>&1
|
|---|
| 264 | printprocesslog "ERROR filloptical.C failed for $opticalfile: timestamp line with more or less than 4 arguments"
|
|---|
| 265 | continue ;;
|
|---|
| 266 | 6) echo " checkfilloptical=$checkfilloptical - ERROR filloptical.C failed for $opticalfile: object line with more or less than 8 arguments" >> $scriptlog 2>&1
|
|---|
| 267 | printprocesslog "ERROR filloptical.C failed for $opticalfile: object line with more or less than 8 arguments"
|
|---|
| 268 | continue ;;
|
|---|
| 269 | *) echo " checkfilloptical=$checkfilloptical - ERROR filloptical.C failed for $opticalfile -> go on with next file" >> $scriptlog 2>&1
|
|---|
| 270 | printprocesslog "ERROR filloptical.C failed for $opticalfile (returned $checkfilloptical)"
|
|---|
| 271 | continue ;;
|
|---|
| 272 | esac
|
|---|
| 273 | done
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | # third part of the script:
|
|---|
| 277 | #update the catalog file magic_favorites.edb
|
|---|
| 278 | printprocesslog "INFO processing new catalog files"
|
|---|
| 279 | echo "Processing new catalog files" >> $scriptlog 2>&1
|
|---|
| 280 | magfav=magic_favorites.edb #catalog filename
|
|---|
| 281 | catalog=$setuppath/$magfav #current catalogfile
|
|---|
| 282 | diff=/tmp/magic_favorites_diff #file to store difference
|
|---|
| 283 |
|
|---|
| 284 | #getting new catalogfiles
|
|---|
| 285 | for (( i=0 ; i < 31 ; i++ ))
|
|---|
| 286 | do
|
|---|
| 287 | date=`date --date "-${i}day" +%Y/%m/%d`
|
|---|
| 288 | path=$subsystempath/cc/$date
|
|---|
| 289 | catfiles=$catfiles" "`find $path -name $magfav -newer $catalog`
|
|---|
| 290 | done
|
|---|
| 291 |
|
|---|
| 292 | for catfile in ${catfiles[@]}
|
|---|
| 293 | do
|
|---|
| 294 | printprocesslog "INFO processing catalog file $catfile"
|
|---|
| 295 | #write information into .diff
|
|---|
| 296 | echo "diff $catfile $catalog" >| $diff
|
|---|
| 297 | diff $catfile $catalog >> $diff
|
|---|
| 298 | #getting differences
|
|---|
| 299 | ins=`cat $diff | grep '>'` #what has been inserted
|
|---|
| 300 | outs=`cat $diff | grep '<'` #what has been removed
|
|---|
| 301 |
|
|---|
| 302 | #check if lines have been inserted
|
|---|
| 303 | if ! [ "$ins" == "" ]
|
|---|
| 304 | then
|
|---|
| 305 | echo "--> catalogfile: "$catfile >> $scriptlog 2>&1
|
|---|
| 306 | echo "the following lines were added:" >> $scriptlog 2>&1
|
|---|
| 307 | cat $diff | grep '>' >> $scriptlog 2>&1
|
|---|
| 308 |
|
|---|
| 309 | #check if lines have been removed
|
|---|
| 310 | if ! [ "$outs" == "" ]
|
|---|
| 311 | then
|
|---|
| 312 | echo "the following lines have been removed" >> $scriptlog 2>&1
|
|---|
| 313 | cat $diff | grep '<' >> $scriptlog 2>&1
|
|---|
| 314 | echo " -> please check the file $catfile" >> $scriptlog 2>&1
|
|---|
| 315 | #inform $adrs about removed lines
|
|---|
| 316 | nail -s 'catalogfile - removed lines' $adrs < $diff
|
|---|
| 317 | printprocesslog "NEWS catalog file: lines have been removed ($catfile)"
|
|---|
| 318 | finish >> $scriptlog 2>&1
|
|---|
| 319 | fi
|
|---|
| 320 |
|
|---|
| 321 | #getting date of new catalogfile from path
|
|---|
| 322 | date=`echo $catfile | cut -d/ -f5-7 | sed -e 's/\///g'`
|
|---|
| 323 |
|
|---|
| 324 | oldcatalogpath=$setuppath/oldcatalogs
|
|---|
| 325 | makedir $oldcatalogpath >> $scriptlog 2>&1
|
|---|
| 326 | #rsync current catalogfile to directory with old catalogfiles including the date of the new catalogfile into the filename
|
|---|
| 327 | if ! rsync -av $catalog $oldcatalogpath/$magfav.$date >> $scriptlog 2>&1
|
|---|
| 328 | then
|
|---|
| 329 | echo "could not do 'rsync -av $catalog $setuppath/oldcatalogs/$magfav.$date' -> exit" >> $scriptlog 2>&1
|
|---|
| 330 | printprocesslog "ERROR rsync of catalog file ($catalog -> $oldcatalogpath/$magfav.$date) didn't work"
|
|---|
| 331 | finish >> $scriptlog 2>&1
|
|---|
| 332 | fi
|
|---|
| 333 | #rsync new catalogfile to current catalogfile
|
|---|
| 334 | if ! rsync -av $catfile $catalog >> $scriptlog 2>&1
|
|---|
| 335 | then
|
|---|
| 336 | echo "could not do 'rsync -av $catfile $catalog' -> exit" >> $scriptlog 2>&1
|
|---|
| 337 | printprocesslog "ERROR rsync of catalog file ($catfile -> $catalog) didn't work"
|
|---|
| 338 | finish >> $scriptlog 2>&1
|
|---|
| 339 | fi
|
|---|
| 340 | #inform $adrs about changes
|
|---|
| 341 | echo "file has been rsynced sucessfully -> sending email" >> $scriptlog 2>&1
|
|---|
| 342 | nail -s 'new catalogfile installed - new lines' $adrs < $diff
|
|---|
| 343 | printprocesslog "NEWS there are new lines in the catalogfile (see $catalog)"
|
|---|
| 344 | continue
|
|---|
| 345 | fi
|
|---|
| 346 | #check if lines have been removed
|
|---|
| 347 | if ! [ "$outs" == "" ]
|
|---|
| 348 | then
|
|---|
| 349 | echo "the following lines have been removed" >> $scriptlog 2>&1
|
|---|
| 350 | cat $diff | grep '<' >> $scriptlog 2>&1
|
|---|
| 351 | echo " -> please check the file $catfile" >> $scriptlog 2>&1
|
|---|
| 352 | #inform $adrs about removed lines
|
|---|
| 353 | nail -s 'catalogfile - removed lines' $adrs < $diff
|
|---|
| 354 | printprocesslog "NEWS catalog file: lines have been removed ($catfile)"
|
|---|
| 355 | finish >> $scriptlog 2>&1
|
|---|
| 356 | fi
|
|---|
| 357 | # echo "nothing has changed ($catfile)" >> $scriptlog 2>&1
|
|---|
| 358 | done
|
|---|
| 359 |
|
|---|
| 360 | finish >> $scriptlog 2>&1
|
|---|
| 361 |
|
|---|