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 |
|
---|
6 | source `dirname $0`/../Sourcefile.sh
|
---|
7 | printprocesslog "INFO starting "$0
|
---|
8 |
|
---|
9 | logfile=$runlogpath"/ZipRawLP-"$datetime".log"
|
---|
10 | date >> $logfile
|
---|
11 |
|
---|
12 | if ! ls /daq/raw >/dev/null 2>&1
|
---|
13 | then
|
---|
14 | printprocesslog "ERROR /daq/raw is not available."
|
---|
15 | finish
|
---|
16 | fi
|
---|
17 |
|
---|
18 | # get dates
|
---|
19 | if [ "$certaindate" != "" ]
|
---|
20 | then
|
---|
21 | getdates $certaindate
|
---|
22 | else
|
---|
23 | # get all night
|
---|
24 | #getdates "all"
|
---|
25 | # get last 3 nights if hour between 7 and 19h, else only current night
|
---|
26 | getdates 3 7 19
|
---|
27 | fi
|
---|
28 |
|
---|
29 | # setup to use ftools
|
---|
30 | source $HEADAS/headas-init.sh
|
---|
31 |
|
---|
32 | delaytime=5
|
---|
33 |
|
---|
34 | # do rsync for rawfiles of these dates
|
---|
35 | for date in ${dates[@]}
|
---|
36 | do
|
---|
37 | echo "" >> $logfile 2>&1
|
---|
38 | rawdir=/daq/raw/$date
|
---|
39 | echo `date`": processing files in "$rawdir >> $logfile 2>&1
|
---|
40 | printprocesslog "INFO processing files in "$rawdir
|
---|
41 | #echo "INFO processing files in "$rawdir
|
---|
42 | # check if data are available from that night
|
---|
43 | if ! [ -d $rawdir ]
|
---|
44 | then
|
---|
45 | echo `date`": no data available in "$rawdir >> $logfile 2>&1
|
---|
46 | printprocesslog "INFO no data available in "$rawdir
|
---|
47 | continue
|
---|
48 | fi
|
---|
49 | zipdir=/loc_data/zipraw/$date
|
---|
50 | if ! [ -d $zipdir ]
|
---|
51 | then
|
---|
52 | # create output directory for zip
|
---|
53 | makedir $zipdir >> $logfile 2>&1
|
---|
54 | fi
|
---|
55 |
|
---|
56 | # find all fits-files starting with the oldest file
|
---|
57 | echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1
|
---|
58 | printprocesslog "INFO finding files to be zipped in "$rawdir"..."
|
---|
59 | fitsfiles=`find $rawdir -type f -name '*fits'| sort `
|
---|
60 |
|
---|
61 | if [ ${#fitsfiles[@]} -eq 0 ]
|
---|
62 | then
|
---|
63 | echo `date`": no files to be zipped in $rawdir..." >> $logfile 2>&1
|
---|
64 | printprocesslog "INFO no files to be zipped in "$rawdir"..."
|
---|
65 | continue
|
---|
66 | fi
|
---|
67 |
|
---|
68 | # loop to zip files
|
---|
69 | echo `date`": zipping files in $rawdir..." >> $logfile 2>&1
|
---|
70 | printprocesslog "INFO zipping files in "$rawdir"..."
|
---|
71 | for file in $fitsfiles
|
---|
72 | do
|
---|
73 | # filename for temporary and final zipfile
|
---|
74 | zipfile=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
|
---|
75 | zipfiletmp=`echo $file | sed -e 's/daq/loc_data/g' -e 's/raw/zipraw/' -e 's/fits/fits.tmp.gz/'`
|
---|
76 | # check if zipped file already exists
|
---|
77 | if [ -e $zipfile ]
|
---|
78 | then
|
---|
79 | continue
|
---|
80 | fi
|
---|
81 |
|
---|
82 | # check if raw file was accessed in the last $delaytime minutes
|
---|
83 | isnew=`find $file -amin -$delaytime`
|
---|
84 | if [ "$isnew" != "" ]
|
---|
85 | then
|
---|
86 | echo $file" is not older than $delaytime min => continue" >> $logfile 2>&1
|
---|
87 | printprocesslog "INFO "$file" is not older than $delaytime min => continue"
|
---|
88 | continue
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # not needed anymore, as only complete files are transferred from newdaq to daq
|
---|
92 | # # check if file is already finished
|
---|
93 | # # original file on daq (if data was taken on daq
|
---|
94 | # origfile=`echo $file | sed -e 's/loc_data/daq/'`
|
---|
95 | # if [ -e $origfile ]
|
---|
96 | # then
|
---|
97 | # # get time of last modification as seconds since Epoch for both files
|
---|
98 | # timeorig=`stat -c %Y $origfile`
|
---|
99 | # timecopy=`stat -c %Y $file`
|
---|
100 | # # compare times
|
---|
101 | # if ! [ $timeorig -eq $timecopy ]
|
---|
102 | # then
|
---|
103 | # # if times are not the same, the file is still open => no zip
|
---|
104 | # echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1
|
---|
105 | # printprocesslog "WARN file "$file" not yet closed => continue"
|
---|
106 | # continue
|
---|
107 | # fi
|
---|
108 | # else
|
---|
109 | # # if the origfile doesn't exist, the data was probably written not on daq but on data
|
---|
110 | # echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1
|
---|
111 | # printprocesslog "WARN file "$file" was probably taken on data and not daq "
|
---|
112 | # fi
|
---|
113 |
|
---|
114 | # # update the raw file with the checksums
|
---|
115 | # ftchecksum update=yes $file >> $logfile 2>&1
|
---|
116 | # check=$?
|
---|
117 | # if [ $check -eq 0 ]
|
---|
118 | # then
|
---|
119 | # echo `date`": file "$file" was updated with the checksums " >> $logfile 2>&1
|
---|
120 | # else
|
---|
121 | # echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")" >> $logfile 2>&1
|
---|
122 | # echo `date`": problem when updating file "$file" (ftchecksum exited with "$check")"
|
---|
123 | # continue
|
---|
124 | # fi
|
---|
125 |
|
---|
126 | echo `date`": zipping "$file" to "$zipfile" ..." >> $logfile 2>&1
|
---|
127 | printprocesslog "INFO zipping "$file" to "$zipfile" ..."
|
---|
128 | #echo "INFO zipping "$file" to "$zipfile" ..."
|
---|
129 | # read setup again to allow for updates of variables defining transfer
|
---|
130 | source `dirname $0`/../Sourcefile.sh
|
---|
131 | # zip file to stdout and pipe it to outputfile
|
---|
132 | echo "pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp" >> $logfile 2>&1
|
---|
133 | pv --rate-limit $limitpigz $file | pigz -1 -c -f -p $numprocpigz > $zipfiletmp
|
---|
134 | statuspigz=( `echo ${PIPESTATUS[@]}` )
|
---|
135 | printprocesslog "DEBUG PIPESTATUS:"${statuspigz[@]}
|
---|
136 | echo " PIPESTATUS:"${statuspigz[@]} >> $logfile 2>&1
|
---|
137 | if [ ${statuspigz[0]} -eq 0 ] && [ ${statuspigz[1]} -eq 0 ]
|
---|
138 | then
|
---|
139 | # if successful, move temporary to final zipfile
|
---|
140 | printprocesslog "INFO move "$zipfiletmp" to "$zipfile" ..."
|
---|
141 | mv -v $zipfiletmp $zipfile >> $logfile 2>&1
|
---|
142 | else
|
---|
143 | # if not successful, remove temporary zipfile
|
---|
144 | printprocesslog "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")."
|
---|
145 | echo "WARN pigz or pv failed (PIPESTATUS:"${statuspigz[@]}")." >> $logfile 2>&1
|
---|
146 | finish
|
---|
147 | printprocesslog "INFO remove "$zipfiletmp"..."
|
---|
148 | rm -v $zipfiletmp >> $logfile 2>&1
|
---|
149 | diskusage=( `df -P /loc_data | grep /loc_data ` )
|
---|
150 | # check if more than ~ 10 GB are left on /loc_data
|
---|
151 | if [ ${diskusage[3]} -lt 10000000 ]
|
---|
152 | then
|
---|
153 | echo "WARN less than 10 GB left on /loc_data on data " >> $logfile 2>&1
|
---|
154 | printprocesslog "WARN less than 10 GB left on /loc_data on data "
|
---|
155 | finish
|
---|
156 | fi
|
---|
157 | fi
|
---|
158 | done
|
---|
159 | done
|
---|
160 | echo "finished zipping..." >> $logfile 2>&1
|
---|
161 | finish
|
---|