1 | #!/bin/bash
|
---|
2 |
|
---|
3 | today=`date +%F`
|
---|
4 | logfile=/home/`whoami`/DataCheck/log/ZipRaw$today.log
|
---|
5 |
|
---|
6 | # get last 3 nights
|
---|
7 | dates=( `date +%Y/%m/%d` `date +%Y/%m/%d --date="-1day"` `date +%Y/%m/%d --date="-2day"` `date +%Y/%m/%d --date="-3day"` )
|
---|
8 |
|
---|
9 | # do rsync for rawfiles of these dates
|
---|
10 | for date in ${dates[@]}
|
---|
11 | do
|
---|
12 | echo "" >> $logfile 2>&1
|
---|
13 | echo "" >> $logfile 2>&1
|
---|
14 | echo "" >> $logfile 2>&1
|
---|
15 | rawdir=/loc_data/raw/$date
|
---|
16 | echo `date`": processing files in "$rawdir >> $logfile
|
---|
17 | # check if data are available from that night
|
---|
18 | if ! [ -d $rawdir ]
|
---|
19 | then
|
---|
20 | echo `date`": no data available in "$rawdir >> $logfile
|
---|
21 | continue
|
---|
22 | fi
|
---|
23 | zipdir=/loc_data/zipraw/$date
|
---|
24 | if ! [ -d $zipdir ]
|
---|
25 | then
|
---|
26 | # create output directory for zip
|
---|
27 | mkdir -pv $zipdir >> $logfile
|
---|
28 | fi
|
---|
29 |
|
---|
30 | # find all fits-files starting with the oldest file
|
---|
31 | echo `date`": finding files to be zipped in $rawdir..." >> $logfile
|
---|
32 | fitsfiles=`find $rawdir -type f -name '*fits'| sort `
|
---|
33 |
|
---|
34 | # loop to zip files
|
---|
35 | echo `date`": zipping files in $rawdir..." >> $logfile
|
---|
36 | for file in $fitsfiles
|
---|
37 | do
|
---|
38 | # filename for temporary and final zipfile
|
---|
39 | zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
|
---|
40 | zipfiletmp=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
|
---|
41 | # check if zipped file already exists
|
---|
42 | if [ -e $zipfile ]
|
---|
43 | then
|
---|
44 | continue
|
---|
45 | fi
|
---|
46 |
|
---|
47 | # check if raw file was accessed in the last 30 minutes
|
---|
48 | isnew=`find $file -amin -30`
|
---|
49 | if [ "$isnew" != "" ]
|
---|
50 | then
|
---|
51 | echo $file" is not older than 30 min => continue" >> $logfile
|
---|
52 | continue
|
---|
53 | fi
|
---|
54 |
|
---|
55 | # check if file is already finished
|
---|
56 | # original file on daq (if data was taken on daq
|
---|
57 | origfile=`echo $file | sed -e 's/loc_data/daq/'`
|
---|
58 | if [ -e $origfile ]
|
---|
59 | then
|
---|
60 | # get time of last modification as seconds since Epoch for both files
|
---|
61 | timeorig=`stat -c %Y $origfile`
|
---|
62 | timecopy=`stat -c %Y $file`
|
---|
63 | # compare times
|
---|
64 | if ! [ $timeorig -eq $timecopy ]
|
---|
65 | then
|
---|
66 | # if times are not the same, the file is still open => no zip
|
---|
67 | echo `date`": file "$file" not yet closed => continue" >> $logfile
|
---|
68 | continue
|
---|
69 | fi
|
---|
70 | else
|
---|
71 | # if the origfile doesn't exist, the data was probably written not on daq but on data
|
---|
72 | echo `date`": file "$file" was probably taken on data and not daq " >> $logfile
|
---|
73 | fi
|
---|
74 |
|
---|
75 | echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile
|
---|
76 | # zip file to stdout and pipe it to outputfile
|
---|
77 | if pigz -1 -c -f $file > $zipfiletmp;
|
---|
78 | then
|
---|
79 | # if successful, move temporary to final zipfile
|
---|
80 | mv -v $zipfiletmp $zipfile >> $logfile
|
---|
81 | else
|
---|
82 | # if not successful, remove temporary zipfile
|
---|
83 | rm -v $zipfiletmp >> $logfile
|
---|
84 | fi
|
---|
85 | done
|
---|
86 | done
|
---|
87 |
|
---|
88 |
|
---|