11 |
{ |
{ |
12 |
echo |
echo |
13 |
echo "Usage: $0 [OPTIONS]" |
echo "Usage: $0 [OPTIONS]" |
14 |
echo |
echo |
15 |
echo "where possible OPTIONS are:" |
echo "where possible OPTIONS are:" |
16 |
echo " (-h|-help) print usage" |
echo " (-h|-help) print usage" |
17 |
echo " (-s|-silent) silent mode" |
echo " (-s|-silent) silent mode" |
19 |
echo " (-i |-ind )DIR get mpack-created emails from DIR" |
echo " (-i |-ind )DIR get mpack-created emails from DIR" |
20 |
echo " [def=\"$INDIR\"]" |
echo " [def=\"$INDIR\"]" |
21 |
echo " (-o |-outd )DIR write the data to DIR" |
echo " (-o |-outd )DIR write the data to DIR" |
22 |
echo " [def=\"$OUTDIR\"]" |
echo " [def=\"$BASEDIR/$monthDir\"]" |
23 |
echo " (-t |-tempd )DIR use temporary directory DIR" |
echo " (-t |-tempd )DIR use temporary directory DIR" |
24 |
echo " [def=\"$TEMPDIR\"]" |
echo " [def=\"$TEMPDIR\"]" |
25 |
echo " (-u |-unpack )EXE use executable EXE to unpack e-mails" |
echo " (-u |-unpack )EXE use executable EXE to unpack e-mails" |
26 |
echo " [def=\"$MUNPACK\"]" |
echo " [def=\"$MUNPACK\"]" |
27 |
echo " (-a |-addr )ADDR send e-mail to ADDR if Error" |
echo " (-a |-addr )ADDR send e-mail to ADDR if Error" |
28 |
echo " [def='"$ADDRERR"']" |
echo " [def='"$ADDRERR"']" |
29 |
echo |
echo |
30 |
exit 1 |
exit 1 |
31 |
} |
} |
32 |
|
|
33 |
# defaults |
# defaults |
34 |
|
HERE=`pwd` |
35 |
INDIR="/u/u2/jmc/Mail/MITgcm-test" |
INDIR="/u/u2/jmc/Mail/MITgcm-test" |
36 |
OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` |
BASEDIR="/u/u0/httpd/html/testing/results" |
37 |
TEMPDIR=./ptmp |
monthDir=`date +%Y`"_"`date +%m` |
38 |
MUNPACK=munpack |
OUTDIR= |
39 |
ADDRERR= |
ADDRERR= |
40 |
|
MUNPACK=$HERE/munpack |
41 |
|
UnpTmpD="/var/tmp/m-prts-$USER" |
42 |
|
TR_LIST='TTT.'$$ |
43 |
|
TEMPDIR="/tmp/prc_emails_$USER" |
44 |
|
STDOUT=$TEMPDIR/'outp.'$$ |
45 |
|
ERRMSG=/tmp/tmp.$$ |
46 |
PRT=1 |
PRT=1 |
47 |
|
|
48 |
|
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
49 |
# Parse options |
# Parse options |
50 |
ac_prev= |
ac_prev= |
51 |
for ac_option ; do |
for ac_option ; do |
58 |
fi |
fi |
59 |
|
|
60 |
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` |
ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` |
61 |
|
|
62 |
case $ac_option in |
case $ac_option in |
63 |
|
|
64 |
-help | --help | -h | --h) |
-help | --help | -h | --h) |
65 |
usage ;; |
usage ;; |
66 |
-s | --s | -silent | --silent) |
-s | --s | -silent | --silent) |
67 |
PRT=0 ;; |
PRT=0 ;; |
68 |
-v | --v | -verbose | --verbose) |
-v | --v | -verbose | --verbose) |
69 |
PRT=2 ;; |
PRT=2 ;; |
70 |
|
|
71 |
-ind | --ind | -i | --i) |
-ind | --ind | -i | --i) |
72 |
ac_prev=INDIR ;; |
ac_prev=INDIR ;; |
73 |
--ind=* | -ind=* | --i=* | -i=*) |
--ind=* | -ind=* | --i=* | -i=*) |
74 |
INDIR=$ac_optarg ;; |
INDIR=$ac_optarg ;; |
75 |
|
|
76 |
-outd | --outd | -o | --o) |
-outd | --outd | -o | --o) |
77 |
ac_prev=OUTDIR ;; |
ac_prev=OUTDIR ;; |
78 |
--outd=* | -outd=* | --o=* | -o=*) |
--outd=* | -outd=* | --o=* | -o=*) |
79 |
OUTDIR=$ac_optarg ;; |
OUTDIR=$ac_optarg ;; |
80 |
|
|
81 |
-tempd | --tempd | -t | --t) |
-tempd | --tempd | -t | --t) |
82 |
ac_prev=TEMPDIR ;; |
ac_prev=TEMPDIR ;; |
83 |
--tempd=* | -tempd=* | --t=* | -t=*) |
--tempd=* | -tempd=* | --t=* | -t=*) |
87 |
ac_prev=MUNPACK ;; |
ac_prev=MUNPACK ;; |
88 |
-u=* | --u=* | -unpack=* | --unpack=*) |
-u=* | --u=* | -unpack=* | --unpack=*) |
89 |
MUNPACK=$ac_optarg ;; |
MUNPACK=$ac_optarg ;; |
90 |
|
|
91 |
-a | --a | -addr | --addr) |
-a | --a | -addr | --addr) |
92 |
ac_prev=ADDRERR ;; |
ac_prev=ADDRERR ;; |
93 |
-a=* | --a=* | -addr=* | --addr=*) |
-a=* | --a=* | -addr=* | --addr=*) |
94 |
ADDRERR=$ac_optarg ;; |
ADDRERR=$ac_optarg ;; |
95 |
|
|
96 |
*) |
*) |
97 |
# copy the file list to FL_# |
date |
98 |
echo "Error: don't understand argument \"$ac_option\"" |
echo "Error: don't understand argument \"$ac_option\"" |
99 |
usage |
usage |
100 |
;; |
;; |
101 |
|
|
102 |
esac |
esac |
103 |
|
|
104 |
done |
done |
105 |
|
|
106 |
if test ! -x $MUNPACK ; then |
if test ! -x $MUNPACK ; then |
107 |
echo "ERROR: \"$MUNPACK\" is not executable" |
date |
108 |
exit 2 |
echo "ERROR: \"$MUNPACK\" is not executable" |
109 |
|
exit 2 |
110 |
|
fi |
111 |
|
if test "x$OUTDIR" = x ; then |
112 |
|
OUTDIR="$BASEDIR/$monthDir" |
113 |
|
else |
114 |
|
monthDir=0 |
115 |
fi |
fi |
116 |
if test ! -e $OUTDIR ; then |
if test ! -e $OUTDIR ; then |
117 |
mkdir $OUTDIR |
mkdir $OUTDIR |
118 |
RETVAL=$? |
RETVAL=$? |
119 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
120 |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
date |
121 |
exit 3 |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
122 |
|
exit 3 |
123 |
|
else |
124 |
|
echo "Successfully created new dir: \"$OUTDIR\"" |
125 |
fi |
fi |
126 |
chgrp gcmpack $OUTDIR |
chgrp gcmpack $OUTDIR |
127 |
chmod 775 $OUTDIR |
chmod 775 $OUTDIR |
128 |
fi |
fi |
129 |
|
|
130 |
all_files=`ls -1 $INDIR` |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
131 |
nb_files=`echo "$all_files" | grep -c '^msg\.'` |
|
132 |
|
all_msg=`ls -1 $INDIR` |
133 |
|
nb_msg=`echo "$all_msg" | grep -c '^msg\.'` |
134 |
|
nb_tar=`echo "$all_msg" | grep -c '\.tar\.gz$'` |
135 |
|
nb_files=`expr $nb_msg + $nb_tar` |
136 |
|
|
137 |
if test $PRT = 1 ; then |
if test $PRT = 2 ; then |
138 |
echo "Using OUTDIR=\"$OUTDIR\"" |
echo "Using OUTDIR=\"$OUTDIR\"" |
139 |
echo "Using INDIR=\"$INDIR\"" |
echo "Using INDIR=\"$INDIR\"" |
140 |
echo -n "Unpacking the emails ..." |
echo -n "Unpacking $nb_msg msg + $nb_tar tar-file ("`date` |
141 |
|
if test "x$ADDRERR" != x ; then |
142 |
|
echo -n ", err: $ADDRERR" |
143 |
|
fi |
144 |
|
echo ")" |
145 |
elif test $nb_files != 0 ; then |
elif test $nb_files != 0 ; then |
146 |
echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'" |
echo -n "Unpacking $nb_msg msg + $nb_tar tar-file ("`date` |
147 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
148 |
echo " "`date`" (send msg to '$ADDRERR' if Error)" |
echo -n ", err: $ADDRERR" |
149 |
fi |
fi |
150 |
if test $PRT = 2 ; then echo -n " dir:" ; fi |
echo ")" |
151 |
|
echo " from '$INDIR' to '$OUTDIR'" |
152 |
fi |
fi |
153 |
|
|
154 |
for file in $all_files ; do |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
155 |
|
|
156 |
# create local copy |
#-- process list of message to detect group of multi-part msgs: |
157 |
|
rm -f $TR_LIST |
158 |
|
touch $TR_LIST |
159 |
|
|
160 |
|
flag=0 |
161 |
|
for xx in $all_msg |
162 |
|
do |
163 |
|
in=`grep -c $xx $TR_LIST` |
164 |
|
if test $in = 0 ; then |
165 |
|
it=`echo $xx | grep -c '\.tar\.gz$'` |
166 |
|
if test $it = 1 ; then |
167 |
|
echo $xx >> $TR_LIST |
168 |
|
else |
169 |
|
np=`grep -c 'Content-Type: message/partial' $INDIR/$xx` |
170 |
|
if test $np = 0 ; then |
171 |
|
echo $xx >> $TR_LIST |
172 |
|
else |
173 |
|
l=`sed -n '/Content-Type: message\/partial/=' $INDIR/$xx` |
174 |
|
lp=`expr $l + 1` |
175 |
|
id=`sed -n "$lp p" $INDIR/$xx` |
176 |
|
partM=`( cd $INDIR ; grep -c "$id" msg.* | grep -v ':0$' | sed 's/:1$//' )` |
177 |
|
echo $partM >> $TR_LIST |
178 |
|
if test "x$ADDRERR" != x ; then flag=1 |
179 |
|
echo "multi-parts message:" $partM >> $ERRMSG |
180 |
|
( cd $INDIR ; ls -l $partM ) >> $ERRMSG |
181 |
|
fi |
182 |
|
fi |
183 |
|
fi |
184 |
|
fi |
185 |
|
done |
186 |
|
if test $flag = 1 ; then |
187 |
|
mail -s 'parse_emails Multi-parts msg' $ADDRERR < $ERRMSG |
188 |
|
rm -f $ERRMSG |
189 |
|
fi |
190 |
|
#cat $TR_LIST ; echo '----------------------------------' |
191 |
|
|
192 |
|
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
193 |
|
|
194 |
|
#-- process list of individual + group of multi-part messages |
195 |
|
Nbl=`wc -l $TR_LIST | cut -d ' ' -f 1` |
196 |
|
n=0 |
197 |
|
while [ $n -lt $Nbl ] ; do |
198 |
|
n=`expr $n + 1` |
199 |
|
errFlg=0 ; prcM='' |
200 |
|
grpM=`sed -n "$n p" $TR_LIST` |
201 |
|
nm=`sed -n "$n p" $TR_LIST | wc -w | cut -d ' ' -f 1` |
202 |
|
|
203 |
|
#- create local copy |
204 |
test -e $TEMPDIR && rm -rf $TEMPDIR |
test -e $TEMPDIR && rm -rf $TEMPDIR |
205 |
mkdir $TEMPDIR |
mkdir $TEMPDIR |
206 |
RETVAL=$? |
RETVAL=$? |
207 |
if test "x$RETVAL" = x0 ; then |
if test "x$RETVAL" = x0 ; then |
208 |
cp $INDIR"/"$file $TEMPDIR |
( cd $INDIR ; cp $grpM $TEMPDIR ) |
209 |
RETVAL=$? |
RETVAL=$? |
210 |
fi |
fi |
211 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
212 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
213 |
echo "parsing email error" > tmp.$$ |
echo "error parsing email '$grpM' :" > $ERRMSG |
214 |
echo " processing file: '$INDIR/$file'" >> tmp.$$ |
echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$grpM $TEMPDIR'" | tee -a $ERRMSG |
215 |
echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$ |
echo " returns error $RETVAL" | tee -a $ERRMSG |
216 |
echo " returns error $RETVAL" >> tmp.$$ |
mail -s 'parse_emails err_0' $ADDRERR < $ERRMSG |
217 |
mail -s 'parse_emails err_0' $ADDRERR < tmp.$$ |
rm -f $ERRMSG |
|
rm -f tmp.$$ |
|
218 |
fi |
fi |
219 |
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
( cd $INDIR ; mv -f $grpM ../fail2process ) |
220 |
continue |
continue |
221 |
fi |
fi |
222 |
|
|
223 |
# ignore multi-part messages |
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
224 |
grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 |
it=`echo $grpM | grep -c '\.tar\.gz$'` |
225 |
RETVAL=$? |
if test $it = 1 ; then |
226 |
if test "x$RETVAL" = x0 ; then |
#- nothing to do: already a tar file! |
227 |
|
trOutp=$grpM ; prcM=$grpM |
228 |
|
else |
229 |
|
|
230 |
|
#-check that we have all the parts |
231 |
|
if [ $PRT -ge 1 -a $nm -gt 1 ] ; then |
232 |
|
echo " group (nm=$nm) of multi-parts msg: '$grpM'" |
233 |
|
fi |
234 |
|
for xx in $grpM ; do |
235 |
|
np=`grep 'Content-Type: message/partial' $TEMPDIR/$xx \ |
236 |
|
| sed 's/^Content.*total=//' | sed 's/;$//'` |
237 |
|
if test "x$np" = x -a $nm = 1 ; then np=1 ; fi |
238 |
|
if test "x$np" != "x$nm" ; then |
239 |
|
if test $errFlg = 0 ; then errFlg=1 |
240 |
|
echo "error parsing email '$grpM' :" > $ERRMSG |
241 |
|
fi |
242 |
|
echo " - Error: Number of parts='$np' in $xx but got '$nm' msg-files" \ |
243 |
|
| tee -a $ERRMSG |
244 |
|
fi |
245 |
|
done |
246 |
|
if test $errFlg = 1 ; then |
247 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
248 |
echo "parsing email error" > tmp.$$ |
mail -s 'parse_emails err_1' $ADDRERR < $ERRMSG |
|
echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$ |
|
|
ls -l $INDIR"/"$file >> tmp.$$ |
|
|
mail -s 'parse_emails err_1' $ADDRERR < tmp.$$ |
|
|
rm -f tmp.$$ |
|
249 |
fi |
fi |
250 |
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
rm -f $ERRMSG |
251 |
|
( cd $INDIR ; mv -f $grpM ../fail2process ) |
252 |
continue |
continue |
253 |
fi |
fi |
254 |
|
|
255 |
# munpack |
if test $nm = 1 ; then |
256 |
mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` |
#- unpack single part message: |
257 |
|
xx=$grpM |
258 |
|
prcM=$xx |
259 |
|
if test $PRT = 2 ; then echo " unpack single-part msg: '$xx'" ; fi |
260 |
|
( cd $TEMPDIR ; $MUNPACK $xx > $STDOUT 2>&1 ) |
261 |
|
RETVAL=$? |
262 |
|
if test "x$RETVAL" != x0 ; then errFlg=1 |
263 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
264 |
|
echo " - Error: $MUNPACK $xx returns: $RETVAL" | tee -a $ERRMSG |
265 |
|
ls -l $INDIR"/"$xx >> $ERRMSG |
266 |
|
else |
267 |
|
trOutp=`tail -1 $STDOUT | cut -d ' ' -f 1` |
268 |
|
if test ! -f $TEMPDIR/$trOutp ; then errFlg=1 |
269 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
270 |
|
echo " - Error: Missing output file '$trOutp' from $MUNPACK output:" \ |
271 |
|
| tee -a $ERRMSG |
272 |
|
fi |
273 |
|
fi |
274 |
|
if test $errFlg = 1 ; then |
275 |
|
cat $STDOUT | tee -a $ERRMSG |
276 |
|
echo " <<<-----------------------" |
277 |
|
if test "x$ADDRERR" != x ; then |
278 |
|
mail -s 'parse_emails err_2s' $ADDRERR < $ERRMSG |
279 |
|
fi |
280 |
|
rm -f $ERRMSG |
281 |
|
fi |
282 |
|
rm -f $STDOUT |
283 |
|
|
284 |
|
else |
285 |
|
#- unpack group of multi-parts message: |
286 |
|
|
287 |
|
#-unpack each part, in the right order: |
288 |
|
j=0 |
289 |
|
while [ $j -lt $nm ] ; do |
290 |
|
j=`expr $j + 1` |
291 |
|
#- get the j^th part msg |
292 |
|
xx=`( cd $TEMPDIR ; grep -c "Content-Type: message/partial; number=$j" $grpM \ |
293 |
|
| grep -v ':0$' | sed 's/:1$//' )` |
294 |
|
if test $PRT = 2 ; then |
295 |
|
echo -n " $j : xx='$xx' : " |
296 |
|
grep 'Content-Type: message/partial' $TEMPDIR/$xx | sed 's/Content-Type: //' |
297 |
|
fi |
298 |
|
#- check |
299 |
|
if test ! -f $TEMPDIR/$xx ; then |
300 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
301 |
|
echo " - Error: Missing msg file '$xx' in $TEMPDIR:" | tee -a $ERRMSG |
302 |
|
ls -l $TEMDIR | tee -a $ERRMSG |
303 |
|
errFlg=1 ; echo " <<<-----------------------" |
304 |
|
if test "x$ADDRERR" != x ; then |
305 |
|
mail -s 'parse_emails err_2g' $ADDRERR < $ERRMSG |
306 |
|
fi |
307 |
|
rm -f $ERRMSG |
308 |
|
else |
309 |
|
if test $j = 1 ; then prcM=$xx ; else prcM="$prcM $xx" ; fi |
310 |
|
#- do unpack |
311 |
|
( cd $TEMPDIR ; $MUNPACK $xx > $STDOUT 2>&1 ) |
312 |
|
RETVAL=$? |
313 |
|
if test "x$RETVAL" != x0 ; then errFlg=1 |
314 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
315 |
|
echo " - Error: $MUNPACK $xx returns: $RETVAL" | tee -a $ERRMSG |
316 |
|
ls -l $INDIR"/"$xx | tee -a $ERRMSG |
317 |
|
cat $STDOUT | tee -a $ERRMSG |
318 |
|
errFlg=1 ; echo " <<<-----------------------" |
319 |
|
if test "x$ADDRERR" != x ; then |
320 |
|
mail -s 'parse_emails err_2u' $ADDRERR < $ERRMSG |
321 |
|
fi |
322 |
|
rm -f $ERRMSG |
323 |
|
fi |
324 |
|
fi |
325 |
|
if test $errFlg = 1 ; then j=`expr $nm + 1` ; fi |
326 |
|
|
327 |
|
if [ $j -lt $nm ] ; then |
328 |
|
#- if not last part: |
329 |
|
pfix=`cat $STDOUT | tail -1 | awk '{print $NF}'` |
330 |
|
if test -d $UnpTmpD/$pfix ; then |
331 |
|
lock=$UnpTmpD/$pfix/CT |
332 |
|
if test -e $lock ; then |
333 |
|
if test $PRT = 2 ; then echo " remove lock: $lock" ; fi |
334 |
|
rm -f $lock |
335 |
|
else |
336 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
337 |
|
echo " - Error: lock file '$lock' not found from $MUNPACK output:" \ |
338 |
|
| tee -a $ERRMSG |
339 |
|
cat $STDOUT | tee -a $ERRMSG |
340 |
|
errFlg=1 ; echo " <<<-----------------------" |
341 |
|
fi |
342 |
|
else |
343 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
344 |
|
echo " - Error: found no dir '$UnpTmpD/$pfix' from $MUNPACK output:" \ |
345 |
|
| tee -a $ERRMSG |
346 |
|
cat $STDOUT | tee -a $ERRMSG |
347 |
|
errFlg=1 ; echo " <<<-----------------------" |
348 |
|
fi |
349 |
|
elif [ $j -eq $nm ] ; then |
350 |
|
#- if last part: |
351 |
|
trOutp=`tail -1 $STDOUT | cut -d ' ' -f 1` |
352 |
|
if test ! -f $TEMPDIR/$trOutp ; then |
353 |
|
echo "error parsing email '$xx' :" > $ERRMSG |
354 |
|
echo " - Error: Missing output file '$trOutp' from $MUNPACK output:" \ |
355 |
|
| tee -a $ERRMSG |
356 |
|
cat $STDOUT | tee -a $ERRMSG |
357 |
|
errFlg=1 ; echo " <<<-----------------------" |
358 |
|
fi |
359 |
|
fi |
360 |
|
if [ $errFlg -eq 1 -a $j -le $nm ] ; then j=$nm |
361 |
|
if test "x$ADDRERR" != x ; then |
362 |
|
mail -s 'parse_emails err_2m' $ADDRERR < $ERRMSG |
363 |
|
fi |
364 |
|
rm -f $ERRMSG |
365 |
|
fi |
366 |
|
rm -f $STDOUT |
367 |
|
done |
368 |
|
fi |
369 |
|
#-- in case of error: mv all $grpM msg to "fail2proc" |
370 |
|
if test $errFlg = 1 ; then |
371 |
|
( cd $INDIR ; mv -f $grpM ../fail2process ) |
372 |
|
continue |
373 |
|
fi |
374 |
|
if test $PRT = 2 ; then |
375 |
|
if test -f $TEMPDIR/$trOutp ; then ls -l $TEMPDIR/$trOutp ; fi |
376 |
|
fi |
377 |
|
|
378 |
|
fi |
379 |
|
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
380 |
|
|
381 |
|
#-- un-tar |
382 |
|
#( cd $TEMPDIR ; tar -xzvf $trOutp > $STDOUT ) |
383 |
|
# to remove small files "._mydir" that some MAC OS are adding |
384 |
|
# (for each file or dir) to a tar-file, use option "--exclude=": |
385 |
|
( cd $TEMPDIR ; tar -xzvf $trOutp --exclude="._*" > $STDOUT 2> $ERRMSG ) |
386 |
RETVAL=$? |
RETVAL=$? |
387 |
|
#echo "--- content of file $STDOUT (STDOUT):" |
388 |
|
#cat $STDOUT |
389 |
|
#echo "--- content of file $ERRMSG (ERRMSG):" |
390 |
|
#cat $ERRMSG |
391 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
392 |
|
echo "parsing email error" >> $ERRMSG |
393 |
|
echo " - Error: tar -xzvf $trOutp returns:" $RETVAL | tee -a $ERRMSG |
394 |
|
( cd $INDIR ; ls -l $prcM ) | tee -a $ERRMSG |
395 |
|
ls -l $TEMPDIR/$trOutp | tee -a $ERRMSG |
396 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
397 |
echo "parsing email error" > tmp.$$ |
mail -s 'parse_emails err_3a' $ADDRERR < $ERRMSG |
|
echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$ |
|
|
ls -l $INDIR"/"$file >> tmp.$$ |
|
|
mail -s 'parse_emails err_2' $ADDRERR < tmp.$$ |
|
|
rm -f tmp.$$ |
|
398 |
fi |
fi |
399 |
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
rm -f $ERRMSG |
400 |
|
( cd $INDIR ; mv -f $grpM ../fail2process ) |
401 |
continue |
continue |
402 |
fi |
fi |
403 |
|
test -f $ERRMSG && rm -f $ERRMSG |
404 |
# un-tar |
#-- |
405 |
( cd $TEMPDIR ; tar -xzvf $mun > out ) |
tdir=`cat $STDOUT | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
406 |
RETVAL=$? |
if test -d $TEMPDIR/$tdir ; then |
407 |
if test "x$RETVAL" != x0 ; then |
rm -f $STDOUT |
408 |
|
else |
409 |
|
echo "parsing email error" > $ERRMSG |
410 |
|
echo " - Error: fail to get dir output name 'tdir=$tdir'" | tee -a $ERRMSG |
411 |
|
echo " (cont) from tar file '$TEMPDIR/$trOutp'" | tee -a $ERRMSG |
412 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
413 |
echo "parsing email error" > tmp.$$ |
mail -s 'parse_emails err_3b' $ADDRERR < $ERRMSG |
|
echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$ |
|
|
ls -l $INDIR"/"$file >> tmp.$$ |
|
|
ls -l $mun >> tmp.$$ |
|
|
mail -s 'parse_emails err_3' $ADDRERR < tmp.$$ |
|
|
rm -f tmp.$$ |
|
414 |
fi |
fi |
415 |
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
rm -f $ERRMSG |
416 |
|
( cd $INDIR ; mv -f $grpM ../fail2process ) |
417 |
continue |
continue |
418 |
fi |
fi |
|
tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
|
|
rm -f $TEMPDIR"/out" |
|
419 |
|
|
420 |
# copy to $OUTDIR and rename if necessary |
#-- select which Monthly Output Dir: |
421 |
|
locDir=$OUTDIR |
422 |
|
if test "x$monthDir" != x0 ; then |
423 |
|
dd=`echo $tdir | sed 's/_/ /g' | awk '{ for(i=1;i<=NF;i++) print $i }'\ |
424 |
|
| grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' | tail -1` |
425 |
|
mn=`echo $dd | sed 's/..$//' | sed 's/..$/_&/'` |
426 |
|
if test "x$mn" != "x$monthDir" ; then |
427 |
|
if test "x$mn" = x ; then |
428 |
|
if [ $PRT -ge 1 ] ; then echo " cannot get month from '$tdir'" ; fi |
429 |
|
else |
430 |
|
locDir="$BASEDIR/$mn" |
431 |
|
if test ! -d $locDir ; then |
432 |
|
if [ $PRT -ge 1 ] ; then |
433 |
|
echo "NO DIR: '$locDir' => '$tdir' POSTPONED" |
434 |
|
fi |
435 |
|
if test "x$ADDRERR" != x ; then |
436 |
|
echo "parsing email error" > $ERRMSG |
437 |
|
echo " no dir '$locDir' for outp. '$tdir'" >> $ERRMSG |
438 |
|
( cd $INDIR ; ls -l $prcM ) >> $ERRMSG |
439 |
|
mail -s 'parse_emails err_4' $ADDRERR < $ERRMSG |
440 |
|
rm -f $ERRMSG |
441 |
|
fi |
442 |
|
continue |
443 |
|
fi |
444 |
|
fi |
445 |
|
fi |
446 |
|
fi |
447 |
|
|
448 |
|
#-- copy to $locDir and rename if necessary |
449 |
sdir=$tdir |
sdir=$tdir |
450 |
if test -e $OUTDIR"/"$tdir ; then |
# if test -e $locDir"/"$tdir ; then |
451 |
ad=0 |
sdir=`echo $tdir | sed 's/_[0-9]*$//'` |
452 |
while test -e $OUTDIR"/"$tdir"_"$ad ; do |
ad=0 |
453 |
ad=$(( $ad + 1 )) |
while test -e $locDir"/"$sdir"_"$ad ; do |
454 |
done |
ad=$(( $ad + 1 )) |
455 |
sdir=$tdir"_"$ad |
done |
456 |
|
sdir=$sdir"_"$ad |
457 |
|
# fi |
458 |
|
if [ $PRT -ge 1 ] ; then |
459 |
|
if test "x$locDir" = "x$OUTDIR" |
460 |
|
then echo " '$sdir' ($prcM)" |
461 |
|
else echo " '$sdir' ($prcM) => '$locDir'" |
462 |
|
fi |
463 |
fi |
fi |
464 |
if test $PRT = 2 ; then echo -n " '$sdir'" ; fi |
mv $TEMPDIR"/"$tdir $locDir"/"$sdir > /dev/null 2>&1 |
|
mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 |
|
465 |
RETVAL=$? |
RETVAL=$? |
466 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
467 |
if test "x$ADDRERR" != x ; then |
if test "x$ADDRERR" != x ; then |
468 |
echo "parsing email error" > tmp.$$ |
echo "parsing email error" > $ERRMSG |
469 |
echo "mv $TEMPDIR/$tdir $OUTDIR/$sdir returns error:" $RETVAL >> tmp.$$ |
echo " - Error: mv $TEMPDIR/$tdir $locDir/$sdir returns:" $RETVAL \ |
470 |
echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR >> tmp.$$ |
| tee -a $ERRMSG |
471 |
echo -n "in dir: $OUTDIR : " ; ls -l $OUTDIR >> tmp.$$ |
echo -n " in dir: $TEMPDIR : " ; ls -l $TEMPDIR | tee -a $ERRMSG |
472 |
mail -s 'parse_emails err_4' $ADDRERR < tmp.$$ |
echo -n " in dir: $OUTDIR : " ; ls -l $locDir | tee -a $ERRMSG |
473 |
rm -f tmp.$$ |
mail -s 'parse_emails err_5' $ADDRERR < $ERRMSG |
474 |
|
rm -f $ERRMSG |
475 |
fi |
fi |
476 |
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
( cd $INDIR ; mv -f $grpM ../fail2process ) |
477 |
continue |
continue |
478 |
fi |
fi |
479 |
chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 |
chmod -R a+rx $locDir"/"$sdir > /dev/null 2>&1 |
|
# gzip $OUTDIR"/"$sdir"/output.txt" |
|
480 |
|
|
481 |
# remove the original file |
#-- remove the original message files |
482 |
rm -f $INDIR"/"$file |
( cd $INDIR ; rm -f $grpM ) |
483 |
|
|
484 |
done |
done |
485 |
if test $PRT = 1 ; then echo " done" ; fi |
rm -f $TR_LIST |
486 |
if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi |
if test $PRT = 2 ; then echo " done" ; fi |
487 |
|
|