/[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.23 - (hide annotations) (download)
Wed May 5 15:16:41 2010 UTC (15 years, 2 months ago) by jmc
Branch: MAIN
Changes since 1.22: +3 -3 lines
print msg file name to log file

1 edhill 1.1 #! /usr/bin/env bash
2    
3 jmc 1.23 # $Header: /u/gcmpack/mitgcm.org/front_content/parse_emails,v 1.22 2010/02/17 22:25:46 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 jmc 1.22 TEMPDIR=/tmp/prc_emails
39     ERRMSG=/tmp/tmp.$$
40 jmc 1.14 MUNPACK=munpack
41 jmc 1.12 ADDRERR=
42 jmc 1.10 PRT=1
43 edhill 1.1
44     # Parse options
45     ac_prev=
46     for ac_option ; do
47    
48     # If the previous option needs an argument, assign it.
49     if test -n "$ac_prev"; then
50     eval "$ac_prev=\$ac_option"
51     ac_prev=
52     continue
53     fi
54    
55     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
56 jmc 1.19
57 edhill 1.1 case $ac_option in
58    
59     -help | --help | -h | --h)
60     usage ;;
61 jmc 1.10 -s | --s | -silent | --silent)
62     PRT=0 ;;
63     -v | --v | -verbose | --verbose)
64     PRT=2 ;;
65 edhill 1.1
66     -ind | --ind | -i | --i)
67     ac_prev=INDIR ;;
68     --ind=* | -ind=* | --i=* | -i=*)
69     INDIR=$ac_optarg ;;
70 jmc 1.19
71 edhill 1.1 -outd | --outd | -o | --o)
72     ac_prev=OUTDIR ;;
73     --outd=* | -outd=* | --o=* | -o=*)
74     OUTDIR=$ac_optarg ;;
75 jmc 1.19
76 edhill 1.1 -tempd | --tempd | -t | --t)
77     ac_prev=TEMPDIR ;;
78     --tempd=* | -tempd=* | --t=* | -t=*)
79     TEMPDIR=$ac_optarg ;;
80 jmc 1.14
81     -u | --u | -unpack | --unpack)
82     ac_prev=MUNPACK ;;
83     -u=* | --u=* | -unpack=* | --unpack=*)
84     MUNPACK=$ac_optarg ;;
85 jmc 1.19
86 jmc 1.14 -a | --a | -addr | --addr)
87 jmc 1.12 ac_prev=ADDRERR ;;
88 jmc 1.14 -a=* | --a=* | -addr=* | --addr=*)
89 jmc 1.12 ADDRERR=$ac_optarg ;;
90 jmc 1.14
91 edhill 1.1 *)
92     # copy the file list to FL_#
93 jmc 1.18 date
94 edhill 1.1 echo "Error: don't understand argument \"$ac_option\""
95     usage
96     ;;
97 jmc 1.19
98 edhill 1.1 esac
99 jmc 1.19
100 edhill 1.1 done
101    
102 jmc 1.14 if test ! -x $MUNPACK ; then
103 jmc 1.18 date
104 jmc 1.14 echo "ERROR: \"$MUNPACK\" is not executable"
105     exit 2
106     fi
107 jmc 1.19 if test "x$OUTDIR" = x ; then
108     OUTDIR="$BASEDIR/$monthDir"
109     else
110     monthDir=0
111     fi
112 edhill 1.1 if test ! -e $OUTDIR ; then
113     mkdir $OUTDIR
114     RETVAL=$?
115 jmc 1.15 if test "x$RETVAL" != x0 ; then
116 jmc 1.18 date
117 edhill 1.1 echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"
118 jmc 1.14 exit 3
119 jmc 1.20 else
120     echo "Successfully created new dir: \"$OUTDIR\""
121 edhill 1.1 fi
122 jmc 1.8 chgrp gcmpack $OUTDIR
123     chmod 775 $OUTDIR
124 edhill 1.1 fi
125    
126 jmc 1.10 all_files=`ls -1 $INDIR`
127 jmc 1.11 nb_files=`echo "$all_files" | grep -c '^msg\.'`
128 edhill 1.1
129 jmc 1.10 if test $PRT = 1 ; then
130     echo "Using OUTDIR=\"$OUTDIR\""
131     echo "Using INDIR=\"$INDIR\""
132     echo -n "Unpacking the emails ..."
133     elif test $nb_files != 0 ; then
134 jmc 1.17 echo -n "Unpacking $nb_files emails ("`date`
135 jmc 1.12 if test "x$ADDRERR" != x ; then
136 jmc 1.17 echo -n ", err-msg: '$ADDRERR'"
137 jmc 1.12 fi
138 jmc 1.17 echo ")"
139     echo " from '$INDIR' to '$OUTDIR'"
140 jmc 1.10 fi
141 edhill 1.1
142     for file in $all_files ; do
143    
144 jmc 1.21 #-- create local copy
145 edhill 1.2 test -e $TEMPDIR && rm -rf $TEMPDIR
146 edhill 1.1 mkdir $TEMPDIR
147 jmc 1.15 RETVAL=$?
148     if test "x$RETVAL" = x0 ; then
149     cp $INDIR"/"$file $TEMPDIR
150     RETVAL=$?
151     fi
152     if test "x$RETVAL" != x0 ; then
153     if test "x$ADDRERR" != x ; then
154 jmc 1.22 echo "parsing email error" > $ERRMSG
155     echo " processing file: '$INDIR/$file'" >> $ERRMSG
156     echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> $ERRMSG
157     echo " returns error $RETVAL" >> $ERRMSG
158     mail -s 'parse_emails err_0' $ADDRERR < $ERRMSG
159     rm -f $ERRMSG
160 jmc 1.15 fi
161     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
162     continue
163     fi
164 edhill 1.1
165 jmc 1.21 #-- ignore multi-part messages
166 edhill 1.1 grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
167     RETVAL=$?
168     if test "x$RETVAL" = x0 ; then
169 jmc 1.12 if test "x$ADDRERR" != x ; then
170 jmc 1.22 echo "parsing email error" > $ERRMSG
171     echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> $ERRMSG
172     ls -l $INDIR"/"$file >> $ERRMSG
173     mail -s 'parse_emails err_1' $ADDRERR < $ERRMSG
174     rm -f $ERRMSG
175 jmc 1.12 fi
176     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
177     continue
178 edhill 1.1 fi
179    
180 jmc 1.21 #-- munpack
181 edhill 1.1 mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
182     RETVAL=$?
183     if test "x$RETVAL" != x0 ; then
184 jmc 1.12 if test "x$ADDRERR" != x ; then
185 jmc 1.22 echo "parsing email error" > $ERRMSG
186     echo "$MUNPACK $file returns error: $RETVAL" >> $ERRMSG
187     ls -l $INDIR"/"$file >> $ERRMSG
188     mail -s 'parse_emails err_2' $ADDRERR < $ERRMSG
189     rm -f $ERRMSG
190 jmc 1.12 fi
191     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
192     continue
193 edhill 1.1 fi
194    
195 jmc 1.21 #-- un-tar
196     #( 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 edhill 1.1 RETVAL=$?
201     if test "x$RETVAL" != x0 ; then
202 jmc 1.12 if test "x$ADDRERR" != x ; then
203 jmc 1.22 echo "parsing email error" > $ERRMSG
204     echo "tar -xzvf $mun returns error:" $RETVAL >> $ERRMSG
205     ls -l $INDIR"/"$file >> $ERRMSG
206     ls -l $mun >> $ERRMSG
207     mail -s 'parse_emails err_3a' $ADDRERR < $ERRMSG
208     rm -f $ERRMSG
209 jmc 1.12 fi
210     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
211     continue
212 edhill 1.1 fi
213 edhill 1.2 tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1`
214 jmc 1.21 #tdir=`( cd $TEMPDIR ; /bin/ls -l | grep '^d' | head -1 | awk '{print $NF}' )`
215     if test -d $TEMPDIR/$tdir ; then
216     rm -f $TEMPDIR"/out"
217     else
218     if test "x$ADDRERR" != x ; then
219 jmc 1.22 echo "parsing email error" > $ERRMSG
220     echo " fail to get a dir output name 'tdir=$tdir'" >> $ERRMSG
221     echo " from tar file '$TEMPDIR/$mun'" >> $ERRMSG
222     mail -s 'parse_emails err_3b' $ADDRERR < $ERRMSG
223     rm -f $ERRMSG
224 jmc 1.21 fi
225     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
226     continue
227     fi
228 edhill 1.1
229 jmc 1.21 #-- select which Monthly Output Dir:
230 jmc 1.19 locDir=$OUTDIR
231     if test "x$monthDir" != x0 ; then
232     dd=`echo $tdir | sed 's/_/ /g' | awk '{ for(i=1;i<=NF;i++) print $i }'\
233     | grep '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' | tail -1`
234     mn=`echo $dd | sed 's/..$//' | sed 's/..$/_&/'`
235     if test "x$mn" != "x$monthDir" ; then
236     if test "x$mn" = x ; then
237     if test $PRT = 2 ; then echo " cannot get month from '$tdir'" ; fi
238     else
239     # could comment out this line:
240     #if test $PRT = 2 ; then echo " chg month: '$mn' for '$tdir'" ; fi
241     locDir="$BASEDIR/$mn"
242     if test ! -d $locDir ; then
243     if test $PRT = 2 ; then echo "NO DIR: '$locDir' => '$tdir' POSTPONED" ; fi
244     if test "x$ADDRERR" != x ; then
245 jmc 1.22 echo "parsing email error" > $ERRMSG
246     echo "no dir '$locDir' for outp. '$tdir'" > $ERRMSG
247     ls -l $INDIR"/"$file >> $ERRMSG
248     mail -s 'parse_emails err_4' $ADDRERR < $ERRMSG
249     rm -f $ERRMSG
250 jmc 1.19 fi
251     continue
252     fi
253     fi
254     fi
255     fi
256    
257 jmc 1.21 #-- copy to $locDir and rename if necessary
258 jmc 1.10 sdir=$tdir
259 jmc 1.19 if test -e $locDir"/"$tdir ; then
260 edhill 1.1 ad=0
261 jmc 1.19 while test -e $locDir"/"$tdir"_"$ad ; do
262 edhill 1.1 ad=$(( $ad + 1 ))
263     done
264 jmc 1.10 sdir=$tdir"_"$ad
265 edhill 1.1 fi
266 jmc 1.19 if test $PRT = 2 ; then
267     if test "x$locDir" = "x$OUTDIR"
268 jmc 1.23 then echo " '$sdir' ($file)"
269     else echo " '$sdir' ($file) => '$locDir'"
270 jmc 1.19 fi
271     fi
272     mv $TEMPDIR"/"$tdir $locDir"/"$sdir > /dev/null 2>&1
273 jmc 1.15 RETVAL=$?
274     if test "x$RETVAL" != x0 ; then
275     if test "x$ADDRERR" != x ; then
276 jmc 1.22 echo "parsing email error" > $ERRMSG
277     echo "mv $TEMPDIR/$tdir $locDir/$sdir returns error:" $RETVAL >> $ERRMSG
278     echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR >> $ERRMSG
279     echo -n "in dir: $OUTDIR : " ; ls -l $locDir >> $ERRMSG
280     mail -s 'parse_emails err_5' $ADDRERR < $ERRMSG
281     rm -f $ERRMSG
282 jmc 1.15 fi
283     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
284     continue
285     fi
286 jmc 1.19 chmod -R a+rx $locDir"/"$sdir > /dev/null 2>&1
287 edhill 1.1
288 jmc 1.21 #-- remove the original file
289 edhill 1.1 rm -f $INDIR"/"$file
290    
291     done
292 jmc 1.10 if test $PRT = 1 ; then echo " done" ; fi
293 edhill 1.1

  ViewVC Help
Powered by ViewVC 1.1.22