/[MITgcm]/mitgcm.org/front_content/parse_emails
ViewVC logotype

Diff of /mitgcm.org/front_content/parse_emails

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

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

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.22