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