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

Annotation of /mitgcm.org/front_content/parse_emails

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


Revision 1.19 - (hide annotations) (download)
Mon Feb 2 19:16:45 2009 UTC (16 years, 5 months ago) by jmc
Branch: MAIN
Changes since 1.18: +60 -21 lines
put output in corresponding monthly directory (if exist).

1 edhill 1.1 #! /usr/bin/env bash
2    
3 jmc 1.19 # $Header: /u/gcmpack/mitgcm.org/front_content/parse_emails,v 1.18 2008/09/18 20:13:36 jmc Exp $
4 edhill 1.1 #
5     # The purpose of this script is to parse the emails produced by the
6     # MITgcm/verificaton/testreport script and store the data in a
7     # reasonable location.
8    
9    
10     usage()
11     {
12     echo
13     echo "Usage: $0 [OPTIONS]"
14 jmc 1.19 echo
15 edhill 1.1 echo "where possible OPTIONS are:"
16 jmc 1.10 echo " (-h|-help) print usage"
17     echo " (-s|-silent) silent mode"
18     echo " (-v|-verbose) verbose mode"
19     echo " (-i |-ind )DIR get mpack-created emails from DIR"
20 edhill 1.1 echo " [def=\"$INDIR\"]"
21 jmc 1.10 echo " (-o |-outd )DIR write the data to DIR"
22 jmc 1.19 echo " [def=\"$BASEDIR/$monthDir\"]"
23 jmc 1.10 echo " (-t |-tempd )DIR use temporary directory DIR"
24 edhill 1.1 echo " [def=\"$TEMPDIR\"]"
25 jmc 1.14 echo " (-u |-unpack )EXE use executable EXE to unpack e-mails"
26     echo " [def=\"$MUNPACK\"]"
27 jmc 1.12 echo " (-a |-addr )ADDR send e-mail to ADDR if Error"
28     echo " [def='"$ADDRERR"']"
29 jmc 1.19 echo
30 edhill 1.1 exit 1
31     }
32    
33     # defaults
34 jmc 1.12 INDIR="/u/u2/jmc/Mail/MITgcm-test"
35 jmc 1.19 BASEDIR="/u/u0/httpd/html/testing/results"
36     monthDir=`date +%Y`"_"`date +%m`
37     OUTDIR=
38 edhill 1.1 TEMPDIR=./ptmp
39 jmc 1.14 MUNPACK=munpack
40 jmc 1.12 ADDRERR=
41 jmc 1.10 PRT=1
42 edhill 1.1
43     # Parse options
44     ac_prev=
45     for ac_option ; do
46    
47     # If the previous option needs an argument, assign it.
48     if test -n "$ac_prev"; then
49     eval "$ac_prev=\$ac_option"
50     ac_prev=
51     continue
52     fi
53    
54     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
55 jmc 1.19
56 edhill 1.1 case $ac_option in
57    
58     -help | --help | -h | --h)
59     usage ;;
60 jmc 1.10 -s | --s | -silent | --silent)
61     PRT=0 ;;
62     -v | --v | -verbose | --verbose)
63     PRT=2 ;;
64 edhill 1.1
65     -ind | --ind | -i | --i)
66     ac_prev=INDIR ;;
67     --ind=* | -ind=* | --i=* | -i=*)
68     INDIR=$ac_optarg ;;
69 jmc 1.19
70 edhill 1.1 -outd | --outd | -o | --o)
71     ac_prev=OUTDIR ;;
72     --outd=* | -outd=* | --o=* | -o=*)
73     OUTDIR=$ac_optarg ;;
74 jmc 1.19
75 edhill 1.1 -tempd | --tempd | -t | --t)
76     ac_prev=TEMPDIR ;;
77     --tempd=* | -tempd=* | --t=* | -t=*)
78     TEMPDIR=$ac_optarg ;;
79 jmc 1.14
80     -u | --u | -unpack | --unpack)
81     ac_prev=MUNPACK ;;
82     -u=* | --u=* | -unpack=* | --unpack=*)
83     MUNPACK=$ac_optarg ;;
84 jmc 1.19
85 jmc 1.14 -a | --a | -addr | --addr)
86 jmc 1.12 ac_prev=ADDRERR ;;
87 jmc 1.14 -a=* | --a=* | -addr=* | --addr=*)
88 jmc 1.12 ADDRERR=$ac_optarg ;;
89 jmc 1.14
90 edhill 1.1 *)
91     # copy the file list to FL_#
92 jmc 1.18 date
93 edhill 1.1 echo "Error: don't understand argument \"$ac_option\""
94     usage
95     ;;
96 jmc 1.19
97 edhill 1.1 esac
98 jmc 1.19
99 edhill 1.1 done
100    
101 jmc 1.14 if test ! -x $MUNPACK ; then
102 jmc 1.18 date
103 jmc 1.14 echo "ERROR: \"$MUNPACK\" is not executable"
104     exit 2
105     fi
106 jmc 1.19 if test "x$OUTDIR" = x ; then
107     OUTDIR="$BASEDIR/$monthDir"
108     else
109     monthDir=0
110     fi
111 edhill 1.1 if test ! -e $OUTDIR ; then
112     mkdir $OUTDIR
113     RETVAL=$?
114 jmc 1.15 if test "x$RETVAL" != x0 ; then
115 jmc 1.18 date
116 edhill 1.1 echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"
117 jmc 1.14 exit 3
118 edhill 1.1 fi
119 jmc 1.8 chgrp gcmpack $OUTDIR
120     chmod 775 $OUTDIR
121 edhill 1.1 fi
122    
123 jmc 1.10 all_files=`ls -1 $INDIR`
124 jmc 1.11 nb_files=`echo "$all_files" | grep -c '^msg\.'`
125 edhill 1.1
126 jmc 1.10 if test $PRT = 1 ; then
127     echo "Using OUTDIR=\"$OUTDIR\""
128     echo "Using INDIR=\"$INDIR\""
129     echo -n "Unpacking the emails ..."
130     elif test $nb_files != 0 ; then
131 jmc 1.17 echo -n "Unpacking $nb_files emails ("`date`
132 jmc 1.12 if test "x$ADDRERR" != x ; then
133 jmc 1.17 echo -n ", err-msg: '$ADDRERR'"
134 jmc 1.12 fi
135 jmc 1.17 echo ")"
136     echo " from '$INDIR' to '$OUTDIR'"
137 jmc 1.10 fi
138 edhill 1.1
139     for file in $all_files ; do
140    
141     # create local copy
142 edhill 1.2 test -e $TEMPDIR && rm -rf $TEMPDIR
143 edhill 1.1 mkdir $TEMPDIR
144 jmc 1.15 RETVAL=$?
145     if test "x$RETVAL" = x0 ; then
146     cp $INDIR"/"$file $TEMPDIR
147     RETVAL=$?
148     fi
149     if test "x$RETVAL" != x0 ; then
150     if test "x$ADDRERR" != x ; then
151     echo "parsing email error" > tmp.$$
152     echo " processing file: '$INDIR/$file'" >> tmp.$$
153     echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$
154     echo " returns error $RETVAL" >> tmp.$$
155     mail -s 'parse_emails err_0' $ADDRERR < tmp.$$
156     rm -f tmp.$$
157     fi
158     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
159     continue
160     fi
161 edhill 1.1
162     # ignore multi-part messages
163     grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
164     RETVAL=$?
165     if test "x$RETVAL" = x0 ; then
166 jmc 1.12 if test "x$ADDRERR" != x ; then
167     echo "parsing email error" > tmp.$$
168     echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$
169     ls -l $INDIR"/"$file >> tmp.$$
170     mail -s 'parse_emails err_1' $ADDRERR < tmp.$$
171     rm -f tmp.$$
172     fi
173     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
174     continue
175 edhill 1.1 fi
176    
177     # munpack
178     mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
179     RETVAL=$?
180     if test "x$RETVAL" != x0 ; then
181 jmc 1.12 if test "x$ADDRERR" != x ; then
182     echo "parsing email error" > tmp.$$
183     echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$
184     ls -l $INDIR"/"$file >> tmp.$$
185     mail -s 'parse_emails err_2' $ADDRERR < tmp.$$
186     rm -f tmp.$$
187     fi
188     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
189     continue
190 edhill 1.1 fi
191    
192     # un-tar
193     ( cd $TEMPDIR ; tar -xzvf $mun > out )
194     RETVAL=$?
195     if test "x$RETVAL" != x0 ; then
196 jmc 1.12 if test "x$ADDRERR" != x ; then
197     echo "parsing email error" > tmp.$$
198     echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$
199     ls -l $INDIR"/"$file >> tmp.$$
200     ls -l $mun >> tmp.$$
201     mail -s 'parse_emails err_3' $ADDRERR < tmp.$$
202     rm -f tmp.$$
203     fi
204     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
205     continue
206 edhill 1.1 fi
207 edhill 1.2 tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1`
208 edhill 1.1 rm -f $TEMPDIR"/out"
209    
210 jmc 1.19 # 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 jmc 1.10 sdir=$tdir
240 jmc 1.19 if test -e $locDir"/"$tdir ; then
241 edhill 1.1 ad=0
242 jmc 1.19 while test -e $locDir"/"$tdir"_"$ad ; do
243 edhill 1.1 ad=$(( $ad + 1 ))
244     done
245 jmc 1.10 sdir=$tdir"_"$ad
246 edhill 1.1 fi
247 jmc 1.19 if test $PRT = 2 ; then
248     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 jmc 1.15 RETVAL=$?
255     if test "x$RETVAL" != x0 ; then
256     if test "x$ADDRERR" != x ; then
257     echo "parsing email error" > tmp.$$
258 jmc 1.19 echo "mv $TEMPDIR/$tdir $locDir/$sdir returns error:" $RETVAL >> tmp.$$
259 jmc 1.15 echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR >> tmp.$$
260 jmc 1.19 echo -n "in dir: $OUTDIR : " ; ls -l $locDir >> tmp.$$
261     mail -s 'parse_emails err_5' $ADDRERR < tmp.$$
262 jmc 1.15 rm -f tmp.$$
263     fi
264     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
265     continue
266     fi
267 jmc 1.19 chmod -R a+rx $locDir"/"$sdir > /dev/null 2>&1
268 edhill 1.1
269     # remove the original file
270     rm -f $INDIR"/"$file
271    
272     done
273 jmc 1.10 if test $PRT = 1 ; then echo " done" ; fi
274 edhill 1.1

  ViewVC Help
Powered by ViewVC 1.1.22