1 |
#!/bin/bash |
2 |
|
3 |
source /gpfs/wizard/flight/production/installed/set_pam_env.sh |
4 |
|
5 |
source /gpfs/wizard/UIPnP/UIPnP.sh |
6 |
|
7 |
if [ "$PAM_BIN" == "" ]; then exit; fi |
8 |
|
9 |
export PRODDIR=/gpfs/wizard/flight/production/ |
10 |
|
11 |
export PRERR=$PRODDIR/preRawreader/ |
12 |
|
13 |
export WRKDIR=$PRODDIR/deamons/wrkdir/ |
14 |
|
15 |
export LOGDIR=$PRODDIR/logs/ |
16 |
|
17 |
export CASTOR=gsiftp://lxfarm08.mephi.ru/scratch04/preRawreader/ |
18 |
#export CASTOR=gsiftp://castorgrid.cr.cnaf.infn.it/castor/cnaf.infn.it/pamela/pamela-cnaf/data/flight/preRawreader/ |
19 |
|
20 |
touch $WRKDIR/copy.copylist |
21 |
|
22 |
LOG=$WRKDIR/mcopy.log |
23 |
|
24 |
STEP=$WRKDIR/mcopy.step |
25 |
|
26 |
touch $LOG |
27 |
|
28 |
echo -n " MEPHI DEAMON STARTED AT " >> $LOG; |
29 |
|
30 |
date >> $LOG; |
31 |
|
32 |
echo "600" > $STEP; |
33 |
|
34 |
TIME=`tail -1 $STEP`; |
35 |
|
36 |
STARTPROXY=`date +%s` |
37 |
|
38 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect |
39 |
|
40 |
while [ $TIME -gt 0 ]; do |
41 |
|
42 |
STOPPROXY=`date +%s` |
43 |
|
44 |
let DELTAPROXY=$STOPPROXY-$STARTPROXY |
45 |
|
46 |
if [ $DELTAPROXY -gt 6000 ]; then |
47 |
|
48 |
STARTPROXY=`date +%s` |
49 |
|
50 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect; |
51 |
|
52 |
echo -n "(1) EXPIRED PROXY: " >> $LOG; |
53 |
|
54 |
date >> $LOG; |
55 |
|
56 |
fi |
57 |
|
58 |
edg-gridftp-ls $CASTOR &> $WRKDIR/mcopy.rawlist |
59 |
|
60 |
echo -n "#############>>>> DATE: " >> $LOG; |
61 |
|
62 |
date >> $LOG; |
63 |
|
64 |
for file in `sort $WRKDIR/mcopy.rawlist`; do |
65 |
|
66 |
DONE=0; |
67 |
|
68 |
CHECK=`grep $file $WRKDIR/copy.copylist`; |
69 |
|
70 |
CHECKPAM=`echo $file | grep pam` |
71 |
|
72 |
CHECKPAM2=`echo $file | grep arch` |
73 |
|
74 |
if [ "${CHECK}" != "" ]; then |
75 |
|
76 |
DONE=1; |
77 |
|
78 |
fi; |
79 |
|
80 |
if [ "${CHECKPAM}" == "" ]; then |
81 |
|
82 |
DONE=1; |
83 |
|
84 |
fi; |
85 |
|
86 |
if [ "${CHECKPAM2}" != "" ]; then |
87 |
|
88 |
DONE=1; |
89 |
|
90 |
fi; |
91 |
|
92 |
if [ -f $PRERR/$file ]; then |
93 |
|
94 |
DONE=1; |
95 |
|
96 |
fi; |
97 |
|
98 |
# for sentfile in `cat $WRKDIR/copy.copylist`; do |
99 |
|
100 |
# CHECKPAM=`echo $file | grep pam` |
101 |
|
102 |
# FNAME=`basename $file` |
103 |
|
104 |
# if [ "${FNAME}" == "${sentfile}" ] || [ "${CHECKPAM}" == "" ]; then |
105 |
|
106 |
# DONE=1; |
107 |
|
108 |
# fi; |
109 |
|
110 |
# if [ -s $PRERR/$FNAME ]; then |
111 |
|
112 |
# DONE=1; |
113 |
|
114 |
# fi; |
115 |
|
116 |
# done |
117 |
|
118 |
if [ $DONE -eq 0 ]; then |
119 |
|
120 |
FNAME=`basename $file` |
121 |
|
122 |
STOPPROXY=`date +%s` |
123 |
|
124 |
let DELTAPROXY=$STOPPROXY-$STARTPROXY |
125 |
|
126 |
if [ $DELTAPROXY -gt 6000 ]; then |
127 |
|
128 |
STARTPROXY=`date +%s` |
129 |
|
130 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect |
131 |
|
132 |
echo -n "(2) EXPIRED PROXY: " >> $LOG; |
133 |
|
134 |
date >> $LOG; |
135 |
|
136 |
fi |
137 |
|
138 |
CNAME1=`edg-gridftp-ls --verbose $CASTOR | grep $FNAME`; |
139 |
|
140 |
sleep 30; |
141 |
|
142 |
STOPPROXY=`date +%s` |
143 |
|
144 |
let DELTAPROXY=$STOPPROXY-$STARTPROXY |
145 |
|
146 |
if [ $DELTAPROXY -gt 6000 ]; then |
147 |
|
148 |
STARTPROXY=`date +%s` |
149 |
|
150 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect |
151 |
|
152 |
echo -n "(2) EXPIRED PROXY: " >> $LOG; |
153 |
|
154 |
date >> $LOG; |
155 |
|
156 |
fi |
157 |
|
158 |
CNAME2=`edg-gridftp-ls --verbose $CASTOR | grep $FNAME`; |
159 |
|
160 |
echo $CNAME2 >> $LOG; |
161 |
|
162 |
while [ "$CNAME1" != "$CNAME2" ]; do |
163 |
|
164 |
CNAME2=`edg-gridftp-ls --verbose $CASTOR | grep $FNAME`; |
165 |
|
166 |
sleep 30; |
167 |
|
168 |
echo -n "UNFINISHED FILE: " >> $LOG; |
169 |
|
170 |
date >> $LOG; |
171 |
|
172 |
echo $CNAME1 >> $LOG; |
173 |
|
174 |
echo $CNAME2 >> $LOG; |
175 |
|
176 |
STOPPROXY=`date +%s` |
177 |
|
178 |
let DELTAPROXY=$STOPPROXY-$STARTPROXY |
179 |
|
180 |
if [ $DELTAPROXY -gt 6000 ]; then |
181 |
|
182 |
STARTPROXY=`date +%s` |
183 |
|
184 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect |
185 |
|
186 |
fi |
187 |
|
188 |
CNAME1=`edg-gridftp-ls --verbose $CASTOR | grep $FNAME`; |
189 |
|
190 |
done; |
191 |
|
192 |
echo "Transferring $FNAME from MEPHI!" >> $LOG; |
193 |
|
194 |
STOPPROXY=`date +%s` |
195 |
|
196 |
let DELTAPROXY=$STOPPROXY-$STARTPROXY |
197 |
|
198 |
if [ $DELTAPROXY -gt 6000 ]; then |
199 |
|
200 |
STARTPROXY=`date +%s` |
201 |
|
202 |
voms-proxy-init --voms pamela -pwstdin < $WRKDIR/connect |
203 |
|
204 |
echo -n "(3) EXPIRED PROXY: " >> $LOG; |
205 |
|
206 |
date >> $LOG; |
207 |
|
208 |
fi |
209 |
|
210 |
globus-url-copy $CASTOR/$FNAME file://$PRERR/$FNAME; |
211 |
|
212 |
if [ -s $PRERR/$FNAME ]; then |
213 |
|
214 |
echo "$FNAME succesfully transmitted (I think)" >> $LOG; |
215 |
|
216 |
echo $FNAME >> $WRKDIR/copy.copylist; |
217 |
|
218 |
else |
219 |
|
220 |
echo "Some problem occured for file $FNAME, it is empty" >> $LOG; |
221 |
|
222 |
echo "$FNAME scheduled to be retransmitted" >> $LOG; |
223 |
|
224 |
fi; |
225 |
|
226 |
HOUR=`date +%H`; |
227 |
|
228 |
if [ $HOUR -gt 6 ] && [ $HOUR -lt 19 ]; then |
229 |
|
230 |
echo "Hour is ${HOUR}, day-time I will sleep for 5 seconds" >> $LOG; |
231 |
|
232 |
sleep 5; |
233 |
|
234 |
else |
235 |
|
236 |
echo "Hour is ${HOUR}, night-time I will sleep for 1 seconds" >> $LOG; |
237 |
|
238 |
sleep 1; |
239 |
|
240 |
fi; |
241 |
|
242 |
fi; |
243 |
|
244 |
TIME=`tail -1 $STEP `; |
245 |
|
246 |
if [ $TIME -le 0 ]; then |
247 |
|
248 |
echo -n " EXIT MEPHI DEAMON, RECEIVED TERM SIGNAL " >> $LOG; |
249 |
|
250 |
date >> $LOG; |
251 |
|
252 |
exit; |
253 |
|
254 |
fi |
255 |
|
256 |
done; |
257 |
|
258 |
sleep $TIME; |
259 |
|
260 |
TIME=`tail -1 $STEP`; |
261 |
|
262 |
done; |
263 |
|
264 |
echo -n " EXIT MEPHI DEAMON, RECEIVED TERM SIGNAL " >> $LOG; |
265 |
|
266 |
date >> $LOG; |
267 |
|
268 |
|
269 |
# if [ -f $HDEAM/tr.log ]; then |
270 |
|
271 |
# cat $HDEAM/tr.log | mail -s "Log from retrieving deamon" Emiliano.Mocchiutti@ts.infn.it |
272 |
|
273 |
# rm -f $HDEAM/tr.log; |
274 |
|
275 |
# fi; |
276 |
|