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

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