1 | #!/bin/bash
|
---|
2 |
|
---|
3 | sourceFolder=$1
|
---|
4 | destFolder=$2
|
---|
5 |
|
---|
6 | if [ "$#" != "3" ]
|
---|
7 | then
|
---|
8 | echo "Please specify source and dest folders. and an identifier for the log files Aborting"
|
---|
9 | exit
|
---|
10 | fi
|
---|
11 |
|
---|
12 | if [ $1 == "" ]
|
---|
13 | then
|
---|
14 | echo "Source folder is empty. Aborting"
|
---|
15 | exit
|
---|
16 | fi
|
---|
17 |
|
---|
18 | if [ $2 == "" ]
|
---|
19 | then
|
---|
20 | echo "Dest folder is empty. Aborting"
|
---|
21 | exit
|
---|
22 | fi
|
---|
23 |
|
---|
24 | if [ $3 == "" ]
|
---|
25 | then
|
---|
26 | echo "Identifier for log files empty. Aborting"
|
---|
27 | exit
|
---|
28 | fi
|
---|
29 |
|
---|
30 | #first let's make sure that source and dest folders do exist, and that dest is writable
|
---|
31 | if [ -d $1 ]
|
---|
32 | then
|
---|
33 | sourceFolder=$1
|
---|
34 | else
|
---|
35 | echo "Source folder "$1" does not exist (or cannnot be read.) Aborting"
|
---|
36 | exit
|
---|
37 | fi
|
---|
38 |
|
---|
39 | if [ -d $2 ]
|
---|
40 | then
|
---|
41 | if [ -d $2"/etiennetest" ]
|
---|
42 | then
|
---|
43 | echo "Test folder already exist. Aborting"
|
---|
44 | exit
|
---|
45 | fi
|
---|
46 | mkdir $2"/etiennetest" 2>/dev/null
|
---|
47 | if [ -d $2"/etiennetest" ]
|
---|
48 | then
|
---|
49 | rm -rf $2"/etiennetest"
|
---|
50 | destFolder=$2
|
---|
51 | else
|
---|
52 | echo "Dest folder is not writable. Aborting"
|
---|
53 | exit
|
---|
54 | fi
|
---|
55 | else
|
---|
56 | echo "Dest folder does not exist. Aborting"
|
---|
57 | exit
|
---|
58 | fi
|
---|
59 |
|
---|
60 | #files=`ls $destFolder`
|
---|
61 | #if [ "$files" != "" ]
|
---|
62 | #then
|
---|
63 | # echo "Dest folder is not empty. Aborting"
|
---|
64 | # exit
|
---|
65 | #fi
|
---|
66 | sourceFolder=${sourceFolder%/}
|
---|
67 | destFolder=${destFolder%/}
|
---|
68 | echo "Will start ingesting files from "$sourceFolder" to "$destFolder
|
---|
69 | echo "Will start ingesting files from "$sourceFolder" to "$destFolder >> Rawreport$3.txt
|
---|
70 |
|
---|
71 | #list all the files in sourceFolder, and copy then with the same structure to destfolder
|
---|
72 |
|
---|
73 | entries=`find $sourceFolder -type f -name '*.fits' | sort`
|
---|
74 |
|
---|
75 | for entry in ${entries[@]}
|
---|
76 | do
|
---|
77 | #second construct the destination path.
|
---|
78 | filenameonly=${entry##*/}
|
---|
79 | #first construct the correct file name
|
---|
80 | targetFileName=$filenameonly
|
---|
81 | pathonly=${entry%$filenameonly}
|
---|
82 | extrapathonly=${pathonly#$sourceFolder/}
|
---|
83 | targetFolder=$destFolder"/"$extrapathonly
|
---|
84 | if [ ! -d $targetFolder ]
|
---|
85 | then
|
---|
86 | mkdir -p $targetFolder
|
---|
87 | fi
|
---|
88 |
|
---|
89 | #check if the file already exist there
|
---|
90 | targetFile=$targetFolder"/"$targetFileName
|
---|
91 | interFile="/scratch/"$targetFileName
|
---|
92 | echo "$targetFile"
|
---|
93 | # echo "$interFile"
|
---|
94 | if [ -a $targetFile".gz" ]
|
---|
95 | then
|
---|
96 | echo "File $targetFile already exist. Skipping it" >> Rawreport$3.txt
|
---|
97 | continue
|
---|
98 | fi
|
---|
99 | cp $entry $interFile
|
---|
100 | #if not, do the copying, fixing and checking
|
---|
101 |
|
---|
102 | # grouping=`/home/isdc/lyard/FACT++/fitsdump $targetFile -h 2>/dev/null | grep GROUPING`
|
---|
103 |
|
---|
104 | # grouping=`grep 'GROUPING' "temp.txt"`
|
---|
105 |
|
---|
106 | # if [ "$grouping" == "" ]
|
---|
107 | # then
|
---|
108 |
|
---|
109 | repairRawFile.sh $interFile RawENDerrors$3.txt RawMJDerror$3.txt Rawreport$3.txt RawprocessErrors$3.txt
|
---|
110 |
|
---|
111 | if [ -a $interFile ]
|
---|
112 | then
|
---|
113 | fixRawKeyWords.sh $interFile RawreportTwo$3.txt RawprocessErrors$3.txt
|
---|
114 | result=`fverify $interFile 2>/dev/null | grep '0 error(s)'`
|
---|
115 | if [ "$result" == "" ]
|
---|
116 | then
|
---|
117 | echo "$interFile" >> RawstillHasProblems$3.txt
|
---|
118 | rm $interFile
|
---|
119 | else
|
---|
120 | gzip -1 $interFile
|
---|
121 | cp $interFile".gz" $targetFile".gz"
|
---|
122 | rm $interFile".gz"
|
---|
123 | fi
|
---|
124 | fi
|
---|
125 | done
|
---|
126 |
|
---|
127 | #set the correct permissions
|
---|
128 | find $destFolder -type f -exec chmod 640 {} \;
|
---|
129 | find $destFolder -type d -exec chmod 750 {} \;
|
---|
130 | find $destFolder -exec chgrp fact {} \;
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|