1 |
paus |
1.1 |
#!/bin/bash
|
2 |
|
|
#---------------------------------------------------------------------------------------------------
|
3 |
|
|
# Download a list of files
|
4 |
|
|
#---------------------------------------------------------------------------------------------------
|
5 |
|
|
|
6 |
|
|
# Read the arguments
|
7 |
|
|
echo ""
|
8 |
|
|
echo "downloadSample.sh $*"
|
9 |
|
|
echo ""
|
10 |
|
|
dataDir=$1; shift
|
11 |
|
|
book=$1; shift
|
12 |
|
|
dataset=$1; shift
|
13 |
|
|
target=$1; shift
|
14 |
|
|
nCopyProcs=$1; shift
|
15 |
|
|
condorOutput=$1; shift
|
16 |
paus |
1.3 |
onlyMissing=$1; shift
|
17 |
|
|
|
18 |
|
|
DN=`grid-proxy-info -subject`
|
19 |
paus |
1.1 |
|
20 |
|
|
# Prepare environment
|
21 |
|
|
echo " "
|
22 |
|
|
echo " Process dataset: $dataset of book: $book"
|
23 |
|
|
echo " in directory : $dataDir"
|
24 |
|
|
echo " to target : $target"
|
25 |
|
|
echo " n copy procs : $nCopyProcs"
|
26 |
|
|
echo " condor output: $condorOutput"
|
27 |
paus |
1.3 |
echo " only missing : $onlyMissing"
|
28 |
paus |
1.1 |
|
29 |
|
|
mkdir -p $condorOutput/$book/$dataset
|
30 |
paus |
1.3 |
mkdir -p $target/$book/$dataset
|
31 |
|
|
chmod a+w $target/$book/$dataset
|
32 |
paus |
1.1 |
script=`which downloadFiles.sh`
|
33 |
|
|
|
34 |
paus |
1.3 |
# cleanup our lists and remake a clean one
|
35 |
paus |
1.1 |
rm -f $condorOutput/$book/$dataset/fileList*.txt*
|
36 |
|
|
|
37 |
paus |
1.3 |
# make list of all local files
|
38 |
|
|
if [ "`echo $HOSTNAME | grep mit.edu`" != "" ] && ( [ "`echo $dataDir | grep /castor/cern.ch`" != "" ] || [ "`echo $target | grep /castor/cern.ch`" != "" ] )
|
39 |
paus |
1.1 |
then
|
40 |
paus |
1.3 |
opt="--simple"
|
41 |
paus |
1.1 |
else
|
42 |
paus |
1.3 |
opt=""
|
43 |
paus |
1.1 |
fi
|
44 |
|
|
|
45 |
paus |
1.3 |
#echo "list $opt $dataDir/$book/$dataset > $condorOutput/$book/$dataset/fileList-all.txt-bak"
|
46 |
|
|
list $opt $dataDir/$book/$dataset > $condorOutput/$book/$dataset/fileList-all.txt-bak
|
47 |
|
|
|
48 |
paus |
1.1 |
# Make sure there is a kerberos ticket available
|
49 |
paus |
1.3 |
id=`id -u`
|
50 |
|
|
cp /tmp/x509up_u${id} ~/.krb5/
|
51 |
paus |
1.1 |
KRB5CCNAME=`klist -5 | grep 'Ticket cache:' | cut -d' ' -f 3`
|
52 |
|
|
if ! [ -z $KRB5CCNAME ]
|
53 |
|
|
then
|
54 |
|
|
mkdir -p ~/.krb5/
|
55 |
|
|
chmod 0 ~/.krb5
|
56 |
|
|
chmod u=rwx ~/.krb5
|
57 |
|
|
file=`echo $KRB5CCNAME | cut -d: -f2`
|
58 |
|
|
if [ -f "$file" ]
|
59 |
|
|
then
|
60 |
|
|
cp $file ~/.krb5/ticket
|
61 |
|
|
else
|
62 |
|
|
echo " ERROR -- missing kerberos ticket ($KRB5CCNAME)."
|
63 |
|
|
exit 1
|
64 |
|
|
fi
|
65 |
|
|
else
|
66 |
|
|
echo " ERROR -- missing kerberos ticket ($KRB5CCNAME)."
|
67 |
|
|
fi
|
68 |
|
|
|
69 |
|
|
# make list of all remote files
|
70 |
|
|
#echo " converting all entries"
|
71 |
|
|
cat $condorOutput/$book/$dataset/fileList-all.txt-bak | grep root | \
|
72 |
|
|
while read line
|
73 |
|
|
do
|
74 |
|
|
size=`echo $line | tr -s ' ' | cut -d ' ' -f 1`
|
75 |
|
|
file=`echo $line | tr -s ' ' | cut -d ' ' -f 2`
|
76 |
|
|
file=`basename $file`
|
77 |
|
|
echo "$size $file" >> $condorOutput/$book/$dataset/fileList-all.txt
|
78 |
|
|
done
|
79 |
|
|
|
80 |
|
|
# make list of all local files
|
81 |
paus |
1.3 |
if [ "`echo $HOSTNAME | grep mit.edu`" != "" ] && ( [ "`echo $dataDir | grep /castor/cern.ch`" != "" ] || [ "`echo $target | grep /castor/cern.ch`" != "" ] )
|
82 |
paus |
1.1 |
then
|
83 |
paus |
1.3 |
opt="--simple"
|
84 |
|
|
else
|
85 |
|
|
opt=""
|
86 |
paus |
1.1 |
fi
|
87 |
paus |
1.3 |
|
88 |
paus |
1.1 |
#echo "list $opt $target/$book/$dataset | grep root > $condorOutput/$book/$dataset/fileList-done.txt"
|
89 |
|
|
list $opt $target/$book/$dataset | grep root > $condorOutput/$book/$dataset/fileList-done.txt
|
90 |
|
|
|
91 |
|
|
# make list of missing files
|
92 |
|
|
rm -f $condorOutput/$book/$dataset/fileList.txt
|
93 |
|
|
touch $condorOutput/$book/$dataset/fileList.txt
|
94 |
|
|
cat $condorOutput/$book/$dataset/fileList-all.txt | grep root | \
|
95 |
|
|
while read line
|
96 |
|
|
do
|
97 |
|
|
size=`echo $line | tr -s ' ' | cut -d ' ' -f 1`
|
98 |
|
|
file=`echo $line | tr -s ' ' | cut -d ' ' -f 2`
|
99 |
paus |
1.3 |
exists=`grep "$file" $condorOutput/$book/$dataset/fileList-done.txt`
|
100 |
paus |
1.1 |
if [ "$exists" == "" ]
|
101 |
|
|
then
|
102 |
paus |
1.3 |
echo " -missing-- $file with $size bytes"
|
103 |
paus |
1.1 |
echo "$size $file" >> $condorOutput/$book/$dataset/fileList.txt
|
104 |
|
|
# else
|
105 |
paus |
1.3 |
# echo " -exists--- $file with $size bytes - exists"
|
106 |
|
|
else
|
107 |
|
|
# now check that size matches
|
108 |
|
|
test=`grep "$size $file" $condorOutput/$book/$dataset/fileList-done.txt`
|
109 |
|
|
if [ "$test" == "" ]
|
110 |
|
|
then
|
111 |
|
|
if [ "$onlyMissing" == "" ]
|
112 |
|
|
then
|
113 |
|
|
echo " -fileSize- $exists (remote: $size)"
|
114 |
|
|
echo "$size $file" >> $condorOutput/$book/$dataset/fileList.txt
|
115 |
|
|
fi
|
116 |
|
|
fi
|
117 |
paus |
1.1 |
fi
|
118 |
|
|
done
|
119 |
|
|
|
120 |
|
|
# construct our job
|
121 |
|
|
nFiles=`wc -l $condorOutput/$book/$dataset/fileList.txt | cut -d ' ' -f1`
|
122 |
|
|
if [ "$nFiles" == "" ] || [ "$nFiles" == "0" ]
|
123 |
|
|
then
|
124 |
|
|
echo " "
|
125 |
|
|
echo " No more files to download. EXIT."
|
126 |
|
|
exit 0
|
127 |
|
|
elif [ $nFiles -lt $nCopyProcs ]
|
128 |
|
|
then
|
129 |
|
|
nCopyProcs=$nFiles
|
130 |
|
|
fi
|
131 |
|
|
nFilesPerJob=$(( $nFiles/$nCopyProcs ))
|
132 |
|
|
echo " n files all : $nFiles"
|
133 |
|
|
echo " n files/proc : $nFilesPerJob"
|
134 |
|
|
|
135 |
|
|
i=1
|
136 |
|
|
next=1
|
137 |
|
|
last=$nFilesPerJob
|
138 |
|
|
|
139 |
paus |
1.3 |
# make sure condor is properly setup for us
|
140 |
|
|
if ! [ -z $CONDOR_LOCATION ]
|
141 |
|
|
then
|
142 |
|
|
unset CONDOR_LOCATION
|
143 |
|
|
export CONDOR_CONFIG=/usr/local/condor/etc/condor_config
|
144 |
|
|
fi
|
145 |
|
|
|
146 |
|
|
# loop over the condor jobs and submit them
|
147 |
paus |
1.1 |
while [ $i -le $nCopyProcs ]
|
148 |
|
|
do
|
149 |
|
|
if [ $i == $nCopyProcs ]
|
150 |
|
|
then
|
151 |
|
|
last=$nFiles
|
152 |
|
|
fi
|
153 |
|
|
|
154 |
|
|
# say what we are going to submit
|
155 |
|
|
echo " downloadFiles.sh $dataDir $book $dataset $target $condorOutput $next $last"
|
156 |
|
|
|
157 |
|
|
logFile=`echo download:$book/$dataset/${next}-${last}.txt | tr '/' '+'`
|
158 |
|
|
logFile=/tmp/$logFile
|
159 |
|
|
rm -f $logFile
|
160 |
|
|
|
161 |
|
|
# prepare the condor_submit files
|
162 |
|
|
cat > submit_$$.cmd <<EOF
|
163 |
|
|
Universe = vanilla
|
164 |
|
|
Requirements = ( (Arch == "X86_64" || Arch == "INTEL") && (OpSys == "LINUX") && (Disk >= DiskUsage) && ((Memory * 1024) >= ImageSize) && (HasFileTransfer) )
|
165 |
|
|
Notify_user = paus@mit.edu
|
166 |
|
|
Notification = Error
|
167 |
|
|
Executable = $script
|
168 |
|
|
Arguments = $dataDir $book $dataset $target $condorOutput $next $last
|
169 |
|
|
Rank = Mips
|
170 |
|
|
GetEnv = True
|
171 |
|
|
Input = /dev/null
|
172 |
|
|
Output = $condorOutput/$book/$dataset/${next}-${last}.out
|
173 |
|
|
Error = $condorOutput/$book/$dataset/${next}-${last}.err
|
174 |
|
|
Log = $logFile
|
175 |
|
|
should_transfer_files = YES
|
176 |
|
|
when_to_transfer_output = ON_EXIT
|
177 |
paus |
1.3 |
|
178 |
|
|
+AccountingGroup = "group_cmsuser.cmsu0284"
|
179 |
|
|
|
180 |
paus |
1.1 |
Queue
|
181 |
|
|
EOF
|
182 |
|
|
|
183 |
paus |
1.3 |
#+x509userproxysubject = $DN
|
184 |
|
|
|
185 |
paus |
1.1 |
# submit the jobs
|
186 |
|
|
condor_submit submit_$$.cmd >& /dev/null #>& lastSub
|
187 |
|
|
#cat submit_$$.cmd
|
188 |
|
|
rm submit_$$.cmd
|
189 |
|
|
|
190 |
|
|
# update counters
|
191 |
|
|
next=$(( $next + $nFilesPerJob ))
|
192 |
|
|
last=$(( $last + $nFilesPerJob ))
|
193 |
|
|
i=$(( $i + 1 ))
|
194 |
|
|
done
|
195 |
|
|
|
196 |
|
|
exit 0
|