source: trunk/DataCheck/ZipRawData.sh@ 12788

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