/[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.4 by edhill, Wed Jun 22 13:39:42 2005 UTC revision 1.15 by jmc, Thu Feb 28 20:03:45 2008 UTC
# Line 13  usage() Line 13  usage()
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 "  (-help|-h)           print usage"      echo "  (-h|-help)           print usage"
17      echo "  (-ind |-i )DIR       get mpack-created emails from DIR"      echo "  (-s|-silent)         silent mode"
18        echo "  (-v|-verbose)        verbose mode"
19        echo "  (-i |-ind )DIR       get mpack-created emails from DIR"
20      echo "                         [def=\"$INDIR\"]"      echo "                         [def=\"$INDIR\"]"
21      echo "  (-outd |-o )DIR      write the data to DIR"      echo "  (-o |-outd )DIR      write the data to DIR"
22      echo "                         [def=\"$OUTDIR\"]"      echo "                         [def=\"$OUTDIR\"]"
23      echo "  (-tempd |-t )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=/usr/local/bin/munpack  MUNPACK=munpack
38    ADDRERR=
39    PRT=1
40    
41  #  Parse options  #  Parse options
42  ac_prev=  ac_prev=
# Line 47  for ac_option ; do Line 55  for ac_option ; do
55                    
56          -help | --help | -h | --h)          -help | --help | -h | --h)
57              usage ;;              usage ;;
58            -s | --s | -silent | --silent)
59                PRT=0 ;;
60            -v | --v | -verbose | --verbose)
61                PRT=2 ;;
62                    
63          -ind | --ind | -i | --i)          -ind | --ind | -i | --i)
64              ac_prev=INDIR ;;              ac_prev=INDIR ;;
# Line 62  for ac_option ; do Line 74  for ac_option ; do
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\""
# Line 73  for ac_option ; do Line 95  for ac_option ; do
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
110        chmod 775 $OUTDIR
111  fi  fi
112    
 echo "Using OUTDIR=\"$OUTDIR\""  
 echo "Using INDIR=\"$INDIR\""  
   
113  all_files=`ls -1 $INDIR`  all_files=`ls -1 $INDIR`
114    nb_files=`echo "$all_files" | grep -c '^msg\.'`
115    
116    if test $PRT = 1 ; then
117      echo "Using OUTDIR=\"$OUTDIR\""
118      echo "Using INDIR=\"$INDIR\""
119      echo -n "Unpacking the emails ..."
120    elif test $nb_files != 0 ; then
121      echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'"
122      if test "x$ADDRERR" != x ; then
123         echo " (send msg to '$ADDRERR' if Error)"
124      fi
125      if test $PRT = 2 ; then echo -n " dir:" ; fi
126    fi
127    
 echo -n "Unpacking the emails ..."  
128  for file in $all_files ; do  for file in $all_files ; do
129    
130      #  create local copy      #  create local copy
131      test -e $TEMPDIR  &&  rm -rf $TEMPDIR      test -e $TEMPDIR  &&  rm -rf $TEMPDIR
132      mkdir $TEMPDIR      mkdir $TEMPDIR
133      cp $INDIR"/"$file $TEMPDIR      RETVAL=$?
134        if test "x$RETVAL" = x0 ; then
135          cp $INDIR"/"$file $TEMPDIR
136          RETVAL=$?
137        fi
138        if test "x$RETVAL" != x0 ; then
139          if test "x$ADDRERR" != x ; then
140            echo "parsing email error" > tmp.$$
141            echo " processing file: '$INDIR/$file'" >> tmp.$$
142            echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$
143            echo " returns error $RETVAL" >> tmp.$$
144            mail -s 'parse_emails err_0' $ADDRERR < tmp.$$
145            rm -f tmp.$$
146          fi
147          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
148          continue
149        fi
150    
151      #  ignore multi-part messages      #  ignore multi-part messages
152      grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1      grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
153      RETVAL=$?      RETVAL=$?
154      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
155          continue        if test "x$ADDRERR" != x ; then
156            echo "parsing email error" > tmp.$$
157            echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$
158            ls -l $INDIR"/"$file >> tmp.$$
159            mail -s 'parse_emails err_1' $ADDRERR < tmp.$$
160            rm -f tmp.$$
161          fi
162          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
163          continue
164      fi      fi
165    
166      #  munpack      #  munpack
167      mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`      mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
168      RETVAL=$?      RETVAL=$?
169      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
170          continue        if test "x$ADDRERR" != x ; then
171            echo "parsing email error" > tmp.$$
172            echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$
173            ls -l $INDIR"/"$file >> tmp.$$
174            mail -s 'parse_emails err_2' $ADDRERR < tmp.$$
175            rm -f tmp.$$
176          fi
177          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
178          continue
179      fi      fi
180    
181      #  un-tar      #  un-tar
182      ( cd $TEMPDIR ; tar -xzvf $mun > out )      ( cd $TEMPDIR ; tar -xzvf $mun > out )
183      RETVAL=$?      RETVAL=$?
184      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
185          continue        if test "x$ADDRERR" != x ; then
186            echo "parsing email error" > tmp.$$
187            echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$
188            ls -l $INDIR"/"$file >> tmp.$$
189            ls -l $mun >> tmp.$$
190            mail -s 'parse_emails err_3' $ADDRERR < tmp.$$
191            rm -f tmp.$$
192          fi
193          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
194          continue
195      fi      fi
196      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`
197      rm -f $TEMPDIR"/out"      rm -f $TEMPDIR"/out"
198    
199      #  copy to $OUTDIR and rename if necessary      #  copy to $OUTDIR and rename if necessary
200        sdir=$tdir
201      if test -e $OUTDIR"/"$tdir ; then      if test -e $OUTDIR"/"$tdir ; then
202          ad=0          ad=0
203          while test -e $OUTDIR"/"$tdir"_"$ad ; do          while test -e $OUTDIR"/"$tdir"_"$ad ; do
204              ad=$(( $ad + 1 ))              ad=$(( $ad + 1 ))
205          done          done
206          mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad          sdir=$tdir"_"$ad
     else  
         mv $TEMPDIR"/"$tdir $OUTDIR  
207      fi      fi
208        if test $PRT = 2 ; then echo -n " '$sdir'" ; fi
209      #  If it exists, gzip the "output.txt" file.      mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1
210      if test -r $OUTDIR"/"$tdir"/output.txt" ; then      RETVAL=$?
211          gzip $OUTDIR"/"$tdir"/output.txt"      if test "x$RETVAL" != x0 ; then
212          if test "x$ADDRERR" != x ; then
213            echo "parsing email error" > tmp.$$
214            echo "mv $TEMPDIR/$tdir $OUTDIR/$sdir returns error:" $RETVAL >> tmp.$$
215            echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR  >> tmp.$$
216            echo -n "in dir: $OUTDIR : " ; ls -l $OUTDIR  >> tmp.$$
217            mail -s 'parse_emails err_4' $ADDRERR < tmp.$$
218            rm -f tmp.$$
219          fi
220          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
221          continue
222      fi      fi
223        chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1
224    #   gzip $OUTDIR"/"$sdir"/output.txt"
225    
226      #  remove the original file      #  remove the original file
227      rm -f $INDIR"/"$file      rm -f $INDIR"/"$file
228    
229  done  done
230  echo "  done"  if test $PRT = 1 ; then echo "  done" ; fi
231    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    

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

  ViewVC Help
Powered by ViewVC 1.1.22