/[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.18 by jmc, Thu Sep 18 20:13:36 2008 UTC revision 1.19 by jmc, Mon Feb 2 19:16:45 2009 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    monthDir=`date +%Y`"_"`date +%m`
37    OUTDIR=
38  TEMPDIR=./ptmp  TEMPDIR=./ptmp
39  MUNPACK=munpack  MUNPACK=munpack
40  ADDRERR=  ADDRERR=
# Line 50  for ac_option ; do Line 52  for ac_option ; do
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)
# Line 64  for ac_option ; do Line 66  for ac_option ; do
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=*)
# Line 79  for ac_option ; do Line 81  for ac_option ; do
81              ac_prev=MUNPACK ;;              ac_prev=MUNPACK ;;
82          -u=* | --u=* | -unpack=* | --unpack=*)          -u=* | --u=* | -unpack=* | --unpack=*)
83              MUNPACK=$ac_optarg ;;              MUNPACK=$ac_optarg ;;
84            
85          -a | --a | -addr | --addr)          -a | --a | -addr | --addr)
86              ac_prev=ADDRERR ;;              ac_prev=ADDRERR ;;
87          -a=* | --a=* | -addr=* | --addr=*)          -a=* | --a=* | -addr=* | --addr=*)
# Line 91  for ac_option ; do Line 93  for ac_option ; do
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  if test ! -x $MUNPACK ; then
# Line 101  if test ! -x $MUNPACK ; then Line 103  if test ! -x $MUNPACK ; then
103          echo "ERROR: \"$MUNPACK\" is not executable"          echo "ERROR: \"$MUNPACK\" is not executable"
104          exit 2          exit 2
105  fi  fi
106    if test "x$OUTDIR" = x ; then
107      OUTDIR="$BASEDIR/$monthDir"
108    else
109      monthDir=0
110    fi
111  if test ! -e $OUTDIR ; then  if test ! -e $OUTDIR ; then
112      mkdir $OUTDIR      mkdir $OUTDIR
113      RETVAL=$?      RETVAL=$?
# Line 200  for file in $all_files ; do Line 207  for file in $all_files ; do
207      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`
208      rm -f $TEMPDIR"/out"      rm -f $TEMPDIR"/out"
209    
210      #  copy to $OUTDIR and rename if necessary      #  select which Monthly Output Dir:
211        locDir=$OUTDIR
212        if test "x$monthDir" != x0 ; then
213          dd=`echo $tdir | sed 's/_/ /g' | awk '{ for(i=1;i<=NF;i++) print $i }'\
214                   | grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' | tail -1`
215          mn=`echo $dd | sed 's/..$//' | sed 's/..$/_&/'`
216          if test "x$mn" != "x$monthDir" ; then
217           if test "x$mn" = x ; then
218            if test $PRT = 2 ; then echo " cannot get month from '$tdir'" ; fi
219           else
220           #  could comment out this line:
221           #if test $PRT = 2 ; then echo " chg month: '$mn' for '$tdir'" ; fi
222            locDir="$BASEDIR/$mn"
223            if test ! -d $locDir ; then
224              if test $PRT = 2 ; then echo "NO DIR: '$locDir' => '$tdir' POSTPONED" ; fi
225              if test "x$ADDRERR" != x ; then
226                echo "parsing email error" > tmp.$$
227                echo "no dir '$locDir' for outp. '$tdir'" > tmp.$$
228                ls -l $INDIR"/"$file >> tmp.$$
229                mail -s 'parse_emails err_4' $ADDRERR < tmp.$$
230                rm -f tmp.$$
231              fi
232              continue
233            fi
234           fi
235          fi
236        fi
237    
238        #  copy to $locDir and rename if necessary
239      sdir=$tdir      sdir=$tdir
240      if test -e $OUTDIR"/"$tdir ; then      if test -e $locDir"/"$tdir ; then
241          ad=0          ad=0
242          while test -e $OUTDIR"/"$tdir"_"$ad ; do          while test -e $locDir"/"$tdir"_"$ad ; do
243              ad=$(( $ad + 1 ))              ad=$(( $ad + 1 ))
244          done          done
245          sdir=$tdir"_"$ad          sdir=$tdir"_"$ad
246      fi      fi
247      if test $PRT = 2 ; then echo " '$sdir'" ; fi      if test $PRT = 2 ; then
248      mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1        if test "x$locDir" = "x$OUTDIR"
249          then echo " '$sdir'"
250          else echo " '$sdir' => '$locDir'"
251          fi
252        fi
253        mv $TEMPDIR"/"$tdir $locDir"/"$sdir > /dev/null 2>&1
254      RETVAL=$?      RETVAL=$?
255      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
256        if test "x$ADDRERR" != x ; then        if test "x$ADDRERR" != x ; then
257          echo "parsing email error" > tmp.$$          echo "parsing email error" > tmp.$$
258          echo "mv $TEMPDIR/$tdir $OUTDIR/$sdir returns error:" $RETVAL >> tmp.$$          echo "mv $TEMPDIR/$tdir $locDir/$sdir returns error:" $RETVAL >> tmp.$$
259          echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR  >> tmp.$$          echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR  >> tmp.$$
260          echo -n "in dir: $OUTDIR : " ; ls -l $OUTDIR  >> tmp.$$          echo -n "in dir: $OUTDIR : " ; ls -l $locDir  >> tmp.$$
261          mail -s 'parse_emails err_4' $ADDRERR < tmp.$$          mail -s 'parse_emails err_5' $ADDRERR < tmp.$$
262          rm -f tmp.$$          rm -f tmp.$$
263        fi        fi
264        mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file        mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
265        continue        continue
266      fi      fi
267      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"  
268    
269      #  remove the original file      #  remove the original file
270      rm -f $INDIR"/"$file      rm -f $INDIR"/"$file

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.22