22 |
echo " [def=\"$OUTDIR\"]" |
echo " [def=\"$OUTDIR\"]" |
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" |
26 |
|
echo " [def=\"$MUNPACK\"]" |
27 |
|
echo " (-a |-addr )ADDR send e-mail to ADDR if Error" |
28 |
|
echo " [def='"$ADDRERR"']" |
29 |
echo |
echo |
30 |
exit 1 |
exit 1 |
31 |
} |
} |
32 |
|
|
33 |
# defaults |
# defaults |
34 |
INDIR="/u/edhill/Mail/MITgcm-test" |
INDIR="/u/u2/jmc/Mail/MITgcm-test" |
35 |
OUTDIR= |
OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` |
36 |
TEMPDIR=./ptmp |
TEMPDIR=./ptmp |
37 |
MUNPACK=/u/edhill/local/bin/munpack |
MUNPACK=munpack |
38 |
|
ADDRERR= |
39 |
PRT=1 |
PRT=1 |
40 |
|
|
41 |
# Parse options |
# Parse options |
74 |
ac_prev=TEMPDIR ;; |
ac_prev=TEMPDIR ;; |
75 |
--tempd=* | -tempd=* | --t=* | -t=*) |
--tempd=* | -tempd=* | --t=* | -t=*) |
76 |
TEMPDIR=$ac_optarg ;; |
TEMPDIR=$ac_optarg ;; |
77 |
|
|
78 |
|
-u | --u | -unpack | --unpack) |
79 |
|
ac_prev=MUNPACK ;; |
80 |
|
-u=* | --u=* | -unpack=* | --unpack=*) |
81 |
|
MUNPACK=$ac_optarg ;; |
82 |
|
|
83 |
|
-a | --a | -addr | --addr) |
84 |
|
ac_prev=ADDRERR ;; |
85 |
|
-a=* | --a=* | -addr=* | --addr=*) |
86 |
|
ADDRERR=$ac_optarg ;; |
87 |
|
|
88 |
*) |
*) |
89 |
# copy the file list to FL_# |
# copy the file list to FL_# |
90 |
echo "Error: don't understand argument \"$ac_option\"" |
echo "Error: don't understand argument \"$ac_option\"" |
95 |
|
|
96 |
done |
done |
97 |
|
|
98 |
if test "x$OUTDIR" = x ; then |
if test ! -x $MUNPACK ; then |
99 |
OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` |
echo "ERROR: \"$MUNPACK\" is not executable" |
100 |
|
exit 2 |
101 |
fi |
fi |
102 |
if test ! -e $OUTDIR ; then |
if test ! -e $OUTDIR ; then |
103 |
mkdir $OUTDIR |
mkdir $OUTDIR |
104 |
RETVAL=$? |
RETVAL=$? |
105 |
if test "x$RETVAL" = x ; then |
if test "x$RETVAL" != x0 ; then |
106 |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" |
107 |
exit 1 |
exit 3 |
108 |
fi |
fi |
109 |
chgrp gcmpack $OUTDIR |
chgrp gcmpack $OUTDIR |
110 |
chmod 775 $OUTDIR |
chmod 775 $OUTDIR |
111 |
fi |
fi |
112 |
|
|
113 |
all_files=`ls -1 $INDIR` |
all_files=`ls -1 $INDIR` |
114 |
nb_files=`echo $all_files | grep -c '^msg\.'` |
nb_files=`echo "$all_files" | grep -c '^msg\.'` |
115 |
|
|
116 |
if test $PRT = 1 ; then |
if test $PRT = 1 ; then |
117 |
echo "Using OUTDIR=\"$OUTDIR\"" |
echo "Using OUTDIR=\"$OUTDIR\"" |
118 |
echo "Using INDIR=\"$INDIR\"" |
echo "Using INDIR=\"$INDIR\"" |
119 |
echo -n "Unpacking the emails ..." |
echo -n "Unpacking the emails ..." |
120 |
elif test $nb_files != 0 ; then |
elif test $nb_files != 0 ; then |
121 |
echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'" |
echo -n "Unpacking $nb_files emails ("`date` |
122 |
if test $PRT = 2 ; then echo -n " dir:" ; fi |
if test "x$ADDRERR" != x ; then |
123 |
|
echo -n ", err-msg: '$ADDRERR'" |
124 |
|
fi |
125 |
|
echo ")" |
126 |
|
echo " from '$INDIR' to '$OUTDIR'" |
127 |
fi |
fi |
128 |
|
|
129 |
for file in $all_files ; do |
for file in $all_files ; do |
131 |
# create local copy |
# create local copy |
132 |
test -e $TEMPDIR && rm -rf $TEMPDIR |
test -e $TEMPDIR && rm -rf $TEMPDIR |
133 |
mkdir $TEMPDIR |
mkdir $TEMPDIR |
134 |
cp $INDIR"/"$file $TEMPDIR |
RETVAL=$? |
135 |
|
if test "x$RETVAL" = x0 ; then |
136 |
|
cp $INDIR"/"$file $TEMPDIR |
137 |
|
RETVAL=$? |
138 |
|
fi |
139 |
|
if test "x$RETVAL" != x0 ; then |
140 |
|
if test "x$ADDRERR" != x ; then |
141 |
|
echo "parsing email error" > tmp.$$ |
142 |
|
echo " processing file: '$INDIR/$file'" >> tmp.$$ |
143 |
|
echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$ |
144 |
|
echo " returns error $RETVAL" >> tmp.$$ |
145 |
|
mail -s 'parse_emails err_0' $ADDRERR < tmp.$$ |
146 |
|
rm -f tmp.$$ |
147 |
|
fi |
148 |
|
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
149 |
|
continue |
150 |
|
fi |
151 |
|
|
152 |
# ignore multi-part messages |
# ignore multi-part messages |
153 |
grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 |
grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 |
154 |
RETVAL=$? |
RETVAL=$? |
155 |
if test "x$RETVAL" = x0 ; then |
if test "x$RETVAL" = x0 ; then |
156 |
continue |
if test "x$ADDRERR" != x ; then |
157 |
|
echo "parsing email error" > tmp.$$ |
158 |
|
echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$ |
159 |
|
ls -l $INDIR"/"$file >> tmp.$$ |
160 |
|
mail -s 'parse_emails err_1' $ADDRERR < tmp.$$ |
161 |
|
rm -f tmp.$$ |
162 |
|
fi |
163 |
|
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
164 |
|
continue |
165 |
fi |
fi |
166 |
|
|
167 |
# munpack |
# munpack |
168 |
mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` |
mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` |
169 |
RETVAL=$? |
RETVAL=$? |
170 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
171 |
continue |
if test "x$ADDRERR" != x ; then |
172 |
|
echo "parsing email error" > tmp.$$ |
173 |
|
echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$ |
174 |
|
ls -l $INDIR"/"$file >> tmp.$$ |
175 |
|
mail -s 'parse_emails err_2' $ADDRERR < tmp.$$ |
176 |
|
rm -f tmp.$$ |
177 |
|
fi |
178 |
|
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
179 |
|
continue |
180 |
fi |
fi |
181 |
|
|
182 |
# un-tar |
# un-tar |
183 |
( cd $TEMPDIR ; tar -xzvf $mun > out ) |
( cd $TEMPDIR ; tar -xzvf $mun > out ) |
184 |
RETVAL=$? |
RETVAL=$? |
185 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
186 |
continue |
if test "x$ADDRERR" != x ; then |
187 |
|
echo "parsing email error" > tmp.$$ |
188 |
|
echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$ |
189 |
|
ls -l $INDIR"/"$file >> tmp.$$ |
190 |
|
ls -l $mun >> tmp.$$ |
191 |
|
mail -s 'parse_emails err_3' $ADDRERR < tmp.$$ |
192 |
|
rm -f tmp.$$ |
193 |
|
fi |
194 |
|
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
195 |
|
continue |
196 |
fi |
fi |
197 |
tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` |
198 |
rm -f $TEMPDIR"/out" |
rm -f $TEMPDIR"/out" |
206 |
done |
done |
207 |
sdir=$tdir"_"$ad |
sdir=$tdir"_"$ad |
208 |
fi |
fi |
209 |
if test $PRT = 2 ; then echo -n " '$sdir'" ; fi |
if test $PRT = 2 ; then echo " '$sdir'" ; fi |
210 |
mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 |
mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 |
211 |
|
RETVAL=$? |
212 |
|
if test "x$RETVAL" != x0 ; then |
213 |
|
if test "x$ADDRERR" != x ; then |
214 |
|
echo "parsing email error" > tmp.$$ |
215 |
|
echo "mv $TEMPDIR/$tdir $OUTDIR/$sdir returns error:" $RETVAL >> tmp.$$ |
216 |
|
echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR >> tmp.$$ |
217 |
|
echo -n "in dir: $OUTDIR : " ; ls -l $OUTDIR >> tmp.$$ |
218 |
|
mail -s 'parse_emails err_4' $ADDRERR < tmp.$$ |
219 |
|
rm -f tmp.$$ |
220 |
|
fi |
221 |
|
mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file |
222 |
|
continue |
223 |
|
fi |
224 |
chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 |
chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 |
225 |
# gzip $OUTDIR"/"$sdir"/output.txt" |
# gzip $OUTDIR"/"$sdir"/output.txt" |
226 |
|
|
229 |
|
|
230 |
done |
done |
231 |
if test $PRT = 1 ; then echo " done" ; fi |
if test $PRT = 1 ; then echo " done" ; fi |
|
if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi |
|
|
|
|
|
# echo -n "gzipping all the \"output.txt\" files ..." |
|
|
# ( |
|
|
# cd $OUTDIR |
|
|
# outp=`find . -name output.txt` |
|
|
# if test "x$outp" != x ; then |
|
|
# gzip $outp |
|
|
# fi |
|
|
# ) |
|
|
# echo " done" |
|
|
|
|
|
# echo -n "setting permissions to world-readable ..." |
|
|
# chmod -R a+rx $OUTDIR > /dev/null 2>&1 |
|
|
# echo " done" |
|
|
|
|
232 |
|
|