/[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.6 by edhill, Fri Oct 6 19:49:59 2006 UTC revision 1.13 by jmc, Sun Feb 17 03:20:24 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 "  (-a |-addr )ADDR     send e-mail to ADDR if Error"
26        echo "                         [def='"$ADDRERR"']"
27      echo      echo
28      exit 1      exit 1
29  }  }
30    
31  # defaults  # defaults
32  INDIR="/u/edhill/Mail/MITgcm-test"  INDIR="/u/u2/jmc/Mail/MITgcm-test"
33  OUTDIR=  OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m`
34  TEMPDIR=./ptmp  TEMPDIR=./ptmp
35  MUNPACK=/usr/local/bin/munpack  MUNPACK=/u/u2/jmc/testing/tools_mpack/munpack
36    ADDRERR=
37    PRT=1
38    
39  #  Parse options  #  Parse options
40  ac_prev=  ac_prev=
# Line 47  for ac_option ; do Line 53  for ac_option ; do
53                    
54          -help | --help | -h | --h)          -help | --help | -h | --h)
55              usage ;;              usage ;;
56            -s | --s | -silent | --silent)
57                PRT=0 ;;
58            -v | --v | -verbose | --verbose)
59                PRT=2 ;;
60                    
61          -ind | --ind | -i | --i)          -ind | --ind | -i | --i)
62              ac_prev=INDIR ;;              ac_prev=INDIR ;;
# Line 62  for ac_option ; do Line 72  for ac_option ; do
72              ac_prev=TEMPDIR ;;              ac_prev=TEMPDIR ;;
73          --tempd=* | -tempd=* | --t=* | -t=*)          --tempd=* | -tempd=* | --t=* | -t=*)
74              TEMPDIR=$ac_optarg ;;              TEMPDIR=$ac_optarg ;;
75            -a | --aa | -addr | --addr)
76                ac_prev=ADDRERR ;;
77            -a=* | --aa=* | -addr=* | --addr=*)
78                ADDRERR=$ac_optarg ;;
79                    
80          *)          *)
81              # copy the file list to FL_#              # copy the file list to FL_#
# Line 73  for ac_option ; do Line 87  for ac_option ; do
87            
88  done  done
89    
 if test "x$OUTDIR" = x ; then  
     OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m`  
 fi  
90  if test ! -e $OUTDIR ; then  if test ! -e $OUTDIR ; then
91      mkdir $OUTDIR      mkdir $OUTDIR
92      RETVAL=$?      RETVAL=$?
# Line 83  if test ! -e $OUTDIR ; then Line 94  if test ! -e $OUTDIR ; then
94          echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"          echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"
95          exit 1          exit 1
96      fi      fi
97        chgrp gcmpack $OUTDIR
98        chmod 775 $OUTDIR
99  fi  fi
100    
 echo "Using OUTDIR=\"$OUTDIR\""  
 echo "Using INDIR=\"$INDIR\""  
   
101  all_files=`ls -1 $INDIR`  all_files=`ls -1 $INDIR`
102    nb_files=`echo "$all_files" | grep -c '^msg\.'`
103    
104    if test $PRT = 1 ; then
105      echo "Using OUTDIR=\"$OUTDIR\""
106      echo "Using INDIR=\"$INDIR\""
107      echo -n "Unpacking the emails ..."
108    elif test $nb_files != 0 ; then
109      echo "Unpacking $nb_files emails from '$INDIR' to '$OUTDIR'"
110      if test "x$ADDRERR" != x ; then
111         echo " (send msg to '$ADDRERR' if Error)"
112      fi
113      if test $PRT = 2 ; then echo -n " dir:" ; fi
114    fi
115    
 echo -n "Unpacking the emails ..."  
116  for file in $all_files ; do  for file in $all_files ; do
117    
118      #  create local copy      #  create local copy
# Line 102  for file in $all_files ; do Line 124  for file in $all_files ; do
124      grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1      grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
125      RETVAL=$?      RETVAL=$?
126      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
127          continue        if test "x$ADDRERR" != x ; then
128            echo "parsing email error" > tmp.$$
129            echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$
130            ls -l $INDIR"/"$file >> tmp.$$
131            mail -s 'parse_emails err_1' $ADDRERR < tmp.$$
132            rm -f tmp.$$
133          fi
134          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
135          continue
136      fi      fi
137    
138      #  munpack      #  munpack
139      mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`      mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
140      RETVAL=$?      RETVAL=$?
141      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
142          continue        if test "x$ADDRERR" != x ; then
143            echo "parsing email error" > tmp.$$
144            echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$
145            ls -l $INDIR"/"$file >> tmp.$$
146            mail -s 'parse_emails err_2' $ADDRERR < tmp.$$
147            rm -f tmp.$$
148          fi
149          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
150          continue
151      fi      fi
152    
153      #  un-tar      #  un-tar
154      ( cd $TEMPDIR ; tar -xzvf $mun > out )      ( cd $TEMPDIR ; tar -xzvf $mun > out )
155      RETVAL=$?      RETVAL=$?
156      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
157          continue        if test "x$ADDRERR" != x ; then
158            echo "parsing email error" > tmp.$$
159            echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$
160            ls -l $INDIR"/"$file >> tmp.$$
161            ls -l $mun >> tmp.$$
162            mail -s 'parse_emails err_3' $ADDRERR < tmp.$$
163            rm -f tmp.$$
164          fi
165          mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
166          continue
167      fi      fi
168      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`
169      rm -f $TEMPDIR"/out"      rm -f $TEMPDIR"/out"
170    
171      #  copy to $OUTDIR and rename if necessary      #  copy to $OUTDIR and rename if necessary
172        sdir=$tdir
173      if test -e $OUTDIR"/"$tdir ; then      if test -e $OUTDIR"/"$tdir ; then
174          ad=0          ad=0
175          while test -e $OUTDIR"/"$tdir"_"$ad ; do          while test -e $OUTDIR"/"$tdir"_"$ad ; do
176              ad=$(( $ad + 1 ))              ad=$(( $ad + 1 ))
177          done          done
178          mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1          sdir=$tdir"_"$ad
         chmod -R a+rx $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1  
         gzip $OUTDIR"/"$tdir"_"$ad"/output.txt"  
     else  
         mv $TEMPDIR"/"$tdir $OUTDIR > /dev/null 2>&1  
         chmod -R a+rx $OUTDIR"/"$tdir > /dev/null 2>&1  
         gzip $OUTDIR"/"$tdir"/output.txt"  
179      fi      fi
180        if test $PRT = 2 ; then echo -n " '$sdir'" ; fi
181        mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1
182        chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1
183    #   gzip $OUTDIR"/"$sdir"/output.txt"
184    
185      #  remove the original file      #  remove the original file
186      rm -f $INDIR"/"$file      rm -f $INDIR"/"$file
187    
188  done  done
189  echo "  done"  if test $PRT = 1 ; then echo "  done" ; fi
190    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"  
   
191    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.22