source: trunk/DataCheck/Archive/rawIngest.sh@ 13690

Last change on this file since 13690 was 12871, checked in by lyard, 13 years ago
added more scripts
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/bin/bash
2
3sourceFolder=$1
4destFolder=$2
5
6if [ "$#" != "3" ]
7then
8 echo "Please specify source and dest folders. and an identifier for the log files Aborting"
9 exit
10fi
11
12if [ $1 == "" ]
13then
14 echo "Source folder is empty. Aborting"
15 exit
16fi
17
18if [ $2 == "" ]
19then
20 echo "Dest folder is empty. Aborting"
21 exit
22fi
23
24if [ $3 == "" ]
25then
26 echo "Identifier for log files empty. Aborting"
27 exit
28fi
29
30#first let's make sure that source and dest folders do exist, and that dest is writable
31if [ -d $1 ]
32then
33 sourceFolder=$1
34else
35 echo "Source folder "$1" does not exist (or cannnot be read.) Aborting"
36 exit
37fi
38
39if [ -d $2 ]
40then
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
55else
56 echo "Dest folder does not exist. Aborting"
57 exit
58fi
59
60#files=`ls $destFolder`
61#if [ "$files" != "" ]
62#then
63# echo "Dest folder is not empty. Aborting"
64# exit
65#fi
66sourceFolder=${sourceFolder%/}
67destFolder=${destFolder%/}
68echo "Will start ingesting files from "$sourceFolder" to "$destFolder
69echo "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
73entries=`find $sourceFolder -type f -name '*.fits' | sort`
74
75for entry in ${entries[@]}
76do
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
125done
126
127#set the correct permissions
128find $destFolder -type f -exec chmod 640 {} \;
129find $destFolder -type d -exec chmod 750 {} \;
130find $destFolder -exec chgrp fact {} \;
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Note: See TracBrowser for help on using the repository browser.