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