| 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  | 
     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 | 
| 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 | 
  | 
 BASEDIR="/u/u0/httpd/html/testing/results" | 
| 36 | 
  | 
 monthDir=`date +%Y`"_"`date +%m` | 
| 37 | 
 OUTDIR= | 
 OUTDIR= | 
| 38 | 
 TEMPDIR=./ptmp | 
 TEMPDIR=./ptmp | 
| 39 | 
 MUNPACK=/u/edhill/local/bin/munpack | 
 MUNPACK=munpack | 
| 40 | 
  | 
 ADDRERR= | 
| 41 | 
 PRT=1 | 
 PRT=1 | 
| 42 | 
  | 
  | 
| 43 | 
 #  Parse options | 
 #  Parse options | 
| 52 | 
     fi | 
     fi | 
| 53 | 
  | 
  | 
| 54 | 
     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` | 
     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` | 
| 55 | 
      | 
  | 
| 56 | 
     case $ac_option in | 
     case $ac_option in | 
| 57 | 
          | 
          | 
| 58 | 
         -help | --help | -h | --h) | 
         -help | --help | -h | --h) | 
| 66 | 
             ac_prev=INDIR ;; | 
             ac_prev=INDIR ;; | 
| 67 | 
         --ind=* | -ind=* | --i=* | -i=*) | 
         --ind=* | -ind=* | --i=* | -i=*) | 
| 68 | 
             INDIR=$ac_optarg ;; | 
             INDIR=$ac_optarg ;; | 
| 69 | 
          | 
  | 
| 70 | 
         -outd | --outd | -o | --o) | 
         -outd | --outd | -o | --o) | 
| 71 | 
             ac_prev=OUTDIR ;; | 
             ac_prev=OUTDIR ;; | 
| 72 | 
         --outd=* | -outd=* | --o=* | -o=*) | 
         --outd=* | -outd=* | --o=* | -o=*) | 
| 73 | 
             OUTDIR=$ac_optarg ;; | 
             OUTDIR=$ac_optarg ;; | 
| 74 | 
          | 
  | 
| 75 | 
         -tempd | --tempd | -t | --t) | 
         -tempd | --tempd | -t | --t) | 
| 76 | 
             ac_prev=TEMPDIR ;; | 
             ac_prev=TEMPDIR ;; | 
| 77 | 
         --tempd=* | -tempd=* | --t=* | -t=*) | 
         --tempd=* | -tempd=* | --t=* | -t=*) | 
| 78 | 
             TEMPDIR=$ac_optarg ;; | 
             TEMPDIR=$ac_optarg ;; | 
| 79 | 
          | 
  | 
| 80 | 
  | 
         -u | --u | -unpack | --unpack) | 
| 81 | 
  | 
             ac_prev=MUNPACK ;; | 
| 82 | 
  | 
         -u=* | --u=* | -unpack=* | --unpack=*) | 
| 83 | 
  | 
             MUNPACK=$ac_optarg ;; | 
| 84 | 
  | 
  | 
| 85 | 
  | 
         -a | --a | -addr | --addr) | 
| 86 | 
  | 
             ac_prev=ADDRERR ;; | 
| 87 | 
  | 
         -a=* | --a=* | -addr=* | --addr=*) | 
| 88 | 
  | 
             ADDRERR=$ac_optarg ;; | 
| 89 | 
  | 
  | 
| 90 | 
         *) | 
         *) | 
| 91 | 
             # copy the file list to FL_# | 
             # copy the file list to FL_# | 
| 92 | 
  | 
             date | 
| 93 | 
             echo "Error: don't understand argument \"$ac_option\"" | 
             echo "Error: don't understand argument \"$ac_option\"" | 
| 94 | 
             usage | 
             usage | 
| 95 | 
             ;; | 
             ;; | 
| 96 | 
          | 
  | 
| 97 | 
      esac | 
      esac | 
| 98 | 
       | 
  | 
| 99 | 
 done | 
 done | 
| 100 | 
  | 
  | 
| 101 | 
  | 
 if test ! -x $MUNPACK ; then | 
| 102 | 
  | 
         date | 
| 103 | 
  | 
         echo "ERROR: \"$MUNPACK\" is not executable" | 
| 104 | 
  | 
         exit 2 | 
| 105 | 
  | 
 fi | 
| 106 | 
 if test "x$OUTDIR" = x ; then | 
 if test "x$OUTDIR" = x ; then | 
| 107 | 
     OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` | 
   OUTDIR="$BASEDIR/$monthDir" | 
| 108 | 
  | 
 else | 
| 109 | 
  | 
   monthDir=0 | 
| 110 | 
 fi | 
 fi | 
| 111 | 
 if test ! -e $OUTDIR ; then | 
 if test ! -e $OUTDIR ; then | 
| 112 | 
     mkdir $OUTDIR | 
     mkdir $OUTDIR | 
| 113 | 
     RETVAL=$? | 
     RETVAL=$? | 
| 114 | 
     if test "x$RETVAL" = x ; then | 
     if test "x$RETVAL" != x0 ; then | 
| 115 | 
  | 
         date | 
| 116 | 
         echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" | 
         echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" | 
| 117 | 
         exit 1 | 
         exit 3 | 
| 118 | 
  | 
     else | 
| 119 | 
  | 
         echo "Successfully created new dir: \"$OUTDIR\"" | 
| 120 | 
     fi | 
     fi | 
| 121 | 
     chgrp gcmpack $OUTDIR | 
     chgrp gcmpack $OUTDIR | 
| 122 | 
     chmod 775 $OUTDIR | 
     chmod 775 $OUTDIR | 
| 130 | 
   echo "Using INDIR=\"$INDIR\"" | 
   echo "Using INDIR=\"$INDIR\"" | 
| 131 | 
   echo -n "Unpacking the emails ..." | 
   echo -n "Unpacking the emails ..." | 
| 132 | 
 elif test $nb_files != 0 ; then | 
 elif test $nb_files != 0 ; then | 
| 133 | 
   echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'" | 
   echo -n "Unpacking $nb_files emails ("`date` | 
| 134 | 
   if test $PRT = 2 ; then echo -n " dir:" ; fi | 
   if test "x$ADDRERR" != x ; then | 
| 135 | 
  | 
      echo -n ", err-msg: '$ADDRERR'" | 
| 136 | 
  | 
   fi | 
| 137 | 
  | 
   echo ")" | 
| 138 | 
  | 
   echo " from '$INDIR' to '$OUTDIR'" | 
| 139 | 
 fi | 
 fi | 
| 140 | 
  | 
  | 
| 141 | 
 for file in $all_files ; do | 
 for file in $all_files ; do | 
| 143 | 
     #  create local copy | 
     #  create local copy | 
| 144 | 
     test -e $TEMPDIR  &&  rm -rf $TEMPDIR | 
     test -e $TEMPDIR  &&  rm -rf $TEMPDIR | 
| 145 | 
     mkdir $TEMPDIR | 
     mkdir $TEMPDIR | 
| 146 | 
     cp $INDIR"/"$file $TEMPDIR | 
     RETVAL=$? | 
| 147 | 
  | 
     if test "x$RETVAL" = x0 ; then | 
| 148 | 
  | 
       cp $INDIR"/"$file $TEMPDIR | 
| 149 | 
  | 
       RETVAL=$? | 
| 150 | 
  | 
     fi | 
| 151 | 
  | 
     if test "x$RETVAL" != x0 ; then | 
| 152 | 
  | 
       if test "x$ADDRERR" != x ; then | 
| 153 | 
  | 
         echo "parsing email error" > tmp.$$ | 
| 154 | 
  | 
         echo " processing file: '$INDIR/$file'" >> tmp.$$ | 
| 155 | 
  | 
         echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$ | 
| 156 | 
  | 
         echo " returns error $RETVAL" >> tmp.$$ | 
| 157 | 
  | 
         mail -s 'parse_emails err_0' $ADDRERR < tmp.$$ | 
| 158 | 
  | 
         rm -f tmp.$$ | 
| 159 | 
  | 
       fi | 
| 160 | 
  | 
       mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file | 
| 161 | 
  | 
       continue | 
| 162 | 
  | 
     fi | 
| 163 | 
  | 
  | 
| 164 | 
     #  ignore multi-part messages | 
     #  ignore multi-part messages | 
| 165 | 
     grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 | 
     grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 | 
| 166 | 
     RETVAL=$? | 
     RETVAL=$? | 
| 167 | 
     if test "x$RETVAL" = x0 ; then | 
     if test "x$RETVAL" = x0 ; then | 
| 168 | 
         continue | 
       if test "x$ADDRERR" != x ; then | 
| 169 | 
  | 
         echo "parsing email error" > tmp.$$ | 
| 170 | 
  | 
         echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$ | 
| 171 | 
  | 
         ls -l $INDIR"/"$file >> tmp.$$ | 
| 172 | 
  | 
         mail -s 'parse_emails err_1' $ADDRERR < tmp.$$ | 
| 173 | 
  | 
         rm -f tmp.$$ | 
| 174 | 
  | 
       fi | 
| 175 | 
  | 
       mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file | 
| 176 | 
  | 
       continue | 
| 177 | 
     fi | 
     fi | 
| 178 | 
  | 
  | 
| 179 | 
     #  munpack | 
     #  munpack | 
| 180 | 
     mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` | 
     mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` | 
| 181 | 
     RETVAL=$? | 
     RETVAL=$? | 
| 182 | 
     if test "x$RETVAL" != x0 ; then | 
     if test "x$RETVAL" != x0 ; then | 
| 183 | 
         continue | 
       if test "x$ADDRERR" != x ; then | 
| 184 | 
  | 
         echo "parsing email error" > tmp.$$ | 
| 185 | 
  | 
         echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$ | 
| 186 | 
  | 
         ls -l $INDIR"/"$file >> tmp.$$ | 
| 187 | 
  | 
         mail -s 'parse_emails err_2' $ADDRERR < tmp.$$ | 
| 188 | 
  | 
         rm -f tmp.$$ | 
| 189 | 
  | 
       fi | 
| 190 | 
  | 
       mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file | 
| 191 | 
  | 
       continue | 
| 192 | 
     fi | 
     fi | 
| 193 | 
  | 
  | 
| 194 | 
     #  un-tar | 
     #  un-tar | 
| 195 | 
     ( cd $TEMPDIR ; tar -xzvf $mun > out ) | 
     ( cd $TEMPDIR ; tar -xzvf $mun > out ) | 
| 196 | 
     RETVAL=$? | 
     RETVAL=$? | 
| 197 | 
     if test "x$RETVAL" != x0 ; then | 
     if test "x$RETVAL" != x0 ; then | 
| 198 | 
         continue | 
       if test "x$ADDRERR" != x ; then | 
| 199 | 
  | 
         echo "parsing email error" > tmp.$$ | 
| 200 | 
  | 
         echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$ | 
| 201 | 
  | 
         ls -l $INDIR"/"$file >> tmp.$$ | 
| 202 | 
  | 
         ls -l $mun >> tmp.$$ | 
| 203 | 
  | 
         mail -s 'parse_emails err_3' $ADDRERR < tmp.$$ | 
| 204 | 
  | 
         rm -f tmp.$$ | 
| 205 | 
  | 
       fi | 
| 206 | 
  | 
       mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file | 
| 207 | 
  | 
       continue | 
| 208 | 
     fi | 
     fi | 
| 209 | 
     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` | 
| 210 | 
     rm -f $TEMPDIR"/out" | 
     rm -f $TEMPDIR"/out" | 
| 211 | 
  | 
  | 
| 212 | 
     #  copy to $OUTDIR and rename if necessary | 
     #  select which Monthly Output Dir: | 
| 213 | 
  | 
     locDir=$OUTDIR | 
| 214 | 
  | 
     if test "x$monthDir" != x0 ; then | 
| 215 | 
  | 
       dd=`echo $tdir | sed 's/_/ /g' | awk '{ for(i=1;i<=NF;i++) print $i }'\ | 
| 216 | 
  | 
                | grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' | tail -1` | 
| 217 | 
  | 
       mn=`echo $dd | sed 's/..$//' | sed 's/..$/_&/'` | 
| 218 | 
  | 
       if test "x$mn" != "x$monthDir" ; then | 
| 219 | 
  | 
        if test "x$mn" = x ; then | 
| 220 | 
  | 
         if test $PRT = 2 ; then echo " cannot get month from '$tdir'" ; fi | 
| 221 | 
  | 
        else | 
| 222 | 
  | 
        #  could comment out this line: | 
| 223 | 
  | 
        #if test $PRT = 2 ; then echo " chg month: '$mn' for '$tdir'" ; fi | 
| 224 | 
  | 
         locDir="$BASEDIR/$mn" | 
| 225 | 
  | 
         if test ! -d $locDir ; then | 
| 226 | 
  | 
           if test $PRT = 2 ; then echo "NO DIR: '$locDir' => '$tdir' POSTPONED" ; fi | 
| 227 | 
  | 
           if test "x$ADDRERR" != x ; then | 
| 228 | 
  | 
             echo "parsing email error" > tmp.$$ | 
| 229 | 
  | 
             echo "no dir '$locDir' for outp. '$tdir'" > tmp.$$ | 
| 230 | 
  | 
             ls -l $INDIR"/"$file >> tmp.$$ | 
| 231 | 
  | 
             mail -s 'parse_emails err_4' $ADDRERR < tmp.$$ | 
| 232 | 
  | 
             rm -f tmp.$$ | 
| 233 | 
  | 
           fi | 
| 234 | 
  | 
           continue | 
| 235 | 
  | 
         fi | 
| 236 | 
  | 
        fi | 
| 237 | 
  | 
       fi | 
| 238 | 
  | 
     fi | 
| 239 | 
  | 
  | 
| 240 | 
  | 
     #  copy to $locDir and rename if necessary | 
| 241 | 
     sdir=$tdir | 
     sdir=$tdir | 
| 242 | 
     if test -e $OUTDIR"/"$tdir ; then | 
     if test -e $locDir"/"$tdir ; then | 
| 243 | 
         ad=0 | 
         ad=0 | 
| 244 | 
         while test -e $OUTDIR"/"$tdir"_"$ad ; do | 
         while test -e $locDir"/"$tdir"_"$ad ; do | 
| 245 | 
             ad=$(( $ad + 1 )) | 
             ad=$(( $ad + 1 )) | 
| 246 | 
         done | 
         done | 
| 247 | 
         sdir=$tdir"_"$ad | 
         sdir=$tdir"_"$ad | 
| 248 | 
     fi | 
     fi | 
| 249 | 
     if test $PRT = 2 ; then echo -n " '$sdir'" ; fi | 
     if test $PRT = 2 ; then | 
| 250 | 
     mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 | 
       if test "x$locDir" = "x$OUTDIR" | 
| 251 | 
     chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 | 
       then echo " '$sdir'" | 
| 252 | 
 #   gzip $OUTDIR"/"$sdir"/output.txt" | 
       else echo " '$sdir' => '$locDir'" | 
| 253 | 
  | 
       fi | 
| 254 | 
  | 
     fi | 
| 255 | 
  | 
     mv $TEMPDIR"/"$tdir $locDir"/"$sdir > /dev/null 2>&1 | 
| 256 | 
  | 
     RETVAL=$? | 
| 257 | 
  | 
     if test "x$RETVAL" != x0 ; then | 
| 258 | 
  | 
       if test "x$ADDRERR" != x ; then | 
| 259 | 
  | 
         echo "parsing email error" > tmp.$$ | 
| 260 | 
  | 
         echo "mv $TEMPDIR/$tdir $locDir/$sdir returns error:" $RETVAL >> tmp.$$ | 
| 261 | 
  | 
         echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR  >> tmp.$$ | 
| 262 | 
  | 
         echo -n "in dir: $OUTDIR : " ; ls -l $locDir  >> tmp.$$ | 
| 263 | 
  | 
         mail -s 'parse_emails err_5' $ADDRERR < tmp.$$ | 
| 264 | 
  | 
         rm -f tmp.$$ | 
| 265 | 
  | 
       fi | 
| 266 | 
  | 
       mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file | 
| 267 | 
  | 
       continue | 
| 268 | 
  | 
     fi | 
| 269 | 
  | 
     chmod -R a+rx $locDir"/"$sdir > /dev/null 2>&1 | 
| 270 | 
  | 
  | 
| 271 | 
     #  remove the original file | 
     #  remove the original file | 
| 272 | 
     rm -f $INDIR"/"$file | 
     rm -f $INDIR"/"$file | 
| 273 | 
  | 
  | 
| 274 | 
 done | 
 done | 
| 275 | 
 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" | 
  | 
 | 
  | 
  | 
| 276 | 
  | 
  |