source: trunk/DataCheck/Transfer/ZipRawData.sh@ 13445

Last change on this file since 13445 was 13055, checked in by Daniela Dorner, 13 years ago
adapted scripts to changes in directory structure
  • Property svn:executable set to *
File size: 4.5 KB
Line 
1#!/bin/bash
2
3# this script has been written to run on La Palma on the machine data
4# i.e. paths are only working on this machine
5
6source `dirname $0`/../Sourcefile.sh
7printprocesslog "INFO starting "$0
8
9logfile=$runlogpath"/ZipRawLP-"$datetime".log"
10date >> $logfile
11
12# get last 3 nights
13dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` )
14
15# time rawfile is untouched before further processing (i.e. adding checksum and zipping)
16delaytime=30 #30 minutes
17
18# setup to use ftools
19source $HEADAS/headas-init.sh
20
21# do rsync for rawfiles of these dates
22for date in ${dates[@]}
23do
24 echo "" >> $logfile 2>&1
25 rawdir=/loc_data/raw/$date
26 echo `date`": processing files in "$rawdir >> $logfile 2>&1
27 printprocesslog "INFO processing files in "$rawdir
28 # check if data are available from that night
29 if ! [ -d $rawdir ]
30 then
31 echo `date`": no data available in "$rawdir >> $logfile 2>&1
32 printprocesslog "INFO no data available in "$rawdir
33 continue
34 fi
35 zipdir=/loc_data/zipraw/$date
36 if ! [ -d $zipdir ]
37 then
38 # create output directory for zip
39 makedir $zipdir >> $logfile 2>&1
40 fi
41
42 # find all fits-files starting with the oldest file
43 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
44 printprocesslog "INFO finding files to be zipped in "$rawdir"..."
45 fitsfiles=`find $rawdir -type f -name '*fits'| sort `
46
47 if [ ${#fitsfiles[@]} -eq 0 ]
48 then
49 echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
50 printprocesslog "INFO no files to be zipped in "$rawdir"..."
51 continue
52 fi
53
54 # loop to zip files
55 echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
56 printprocesslog "INFO zipping files in "$rawdir"..."
57 for file in $fitsfiles
58 do
59 # filename for temporary and final zipfile
60 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
61 zipfiletmp=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
62 # check if zipped file already exists
63 if [ -e $zipfile ]
64 then
65 continue
66 fi
67
68 # check if raw file was accessed in the last $delaytime minutes
69 isnew=`find $file -amin -$delaytime`
70 if [ "$isnew" != "" ]
71 then
72 echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
73 printprocesslog "INFO "$file" is not older than $delaytime min => continue"
74 continue
75 fi
76
77 # check if file is already finished
78 # original file on daq (if data was taken on daq
79 origfile=`echo $file | sed -e 's/loc_data/daq/'`
80 if [ -e $origfile ]
81 then
82 # get time of last modification as seconds since Epoch for both files
83 timeorig=`stat -c %Y $origfile`
84 timecopy=`stat -c %Y $file`
85 # compare times
86 if ! [ $timeorig -eq $timecopy ]
87 then
88 # if times are not the same, the file is still open => no zip
89 echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
90 printprocesslog "WARN file "$file" not yet closed => continue"
91 continue
92 fi
93 else
94 # if the origfile doesn't exist, the data was probably written not on daq but on data
95 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
96 printprocesslog "WARN file "$file" was probably taken on data and not daq "
97 fi
98
99# # update the raw file with the checksums
100# ftchecksum update=yes $file >> $logfile 2>&1
101# check=$?
102# if [ $check -eq 0 ]
103# then
104# echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
105# else
106# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
107# echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
108# continue
109# fi
110
111 echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
112 printprocesslog "INFO zipping "$file" to "$zipfile" ..."
113 # zip file to stdout and pipe it to outputfile
114 if pigz -1 -c -f $file > $zipfiletmp
115 then
116 # if successful, move temporary to final zipfile
117 printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
118 mv -v $zipfiletmp $zipfile >> $logfile 2>&1
119 else
120 # if not successful, remove temporary zipfile
121 printprocesslog "INFO remove "$zipfiletmp"..."
122 rm -v $zipfiletmp >> $logfile 2>&1
123 fi
124 done
125done
126echo "finished zipping..." >> $logfile 2>&1
127finish
Note: See TracBrowser for help on using the repository browser.