/[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.14 - (hide annotations) (download)
Tue Feb 26 21:34:00 2008 UTC (17 years, 4 months ago) by jmc
Branch: MAIN
Changes since 1.13: +18 -6 lines
add option to specify which unpack executable to use

1 edhill 1.1 #! /usr/bin/env bash
2    
3 jmc 1.14 # $Header: /u/gcmpack/mitgcm.org/front_content/parse_emails,v 1.13 2008/02/17 03:20:24 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     echo
15     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 edhill 1.1 echo " [def=\"$OUTDIR\"]"
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 edhill 1.1 echo
30     exit 1
31     }
32    
33     # defaults
34 jmc 1.12 INDIR="/u/u2/jmc/Mail/MITgcm-test"
35     OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m`
36 edhill 1.1 TEMPDIR=./ptmp
37 jmc 1.14 MUNPACK=munpack
38 jmc 1.12 ADDRERR=
39 jmc 1.10 PRT=1
40 edhill 1.1
41     # Parse options
42     ac_prev=
43     for ac_option ; do
44    
45     # If the previous option needs an argument, assign it.
46     if test -n "$ac_prev"; then
47     eval "$ac_prev=\$ac_option"
48     ac_prev=
49     continue
50     fi
51    
52     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
53    
54     case $ac_option in
55    
56     -help | --help | -h | --h)
57     usage ;;
58 jmc 1.10 -s | --s | -silent | --silent)
59     PRT=0 ;;
60     -v | --v | -verbose | --verbose)
61     PRT=2 ;;
62 edhill 1.1
63     -ind | --ind | -i | --i)
64     ac_prev=INDIR ;;
65     --ind=* | -ind=* | --i=* | -i=*)
66     INDIR=$ac_optarg ;;
67    
68     -outd | --outd | -o | --o)
69     ac_prev=OUTDIR ;;
70     --outd=* | -outd=* | --o=* | -o=*)
71     OUTDIR=$ac_optarg ;;
72    
73     -tempd | --tempd | -t | --t)
74     ac_prev=TEMPDIR ;;
75     --tempd=* | -tempd=* | --t=* | -t=*)
76     TEMPDIR=$ac_optarg ;;
77 jmc 1.14
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 jmc 1.12 ac_prev=ADDRERR ;;
85 jmc 1.14 -a=* | --a=* | -addr=* | --addr=*)
86 jmc 1.12 ADDRERR=$ac_optarg ;;
87 jmc 1.14
88 edhill 1.1 *)
89     # copy the file list to FL_#
90     echo "Error: don't understand argument \"$ac_option\""
91     usage
92     ;;
93    
94     esac
95    
96     done
97    
98 jmc 1.14 if test ! -x $MUNPACK ; then
99     echo "ERROR: \"$MUNPACK\" is not executable"
100     exit 2
101     fi
102 edhill 1.1 if test ! -e $OUTDIR ; then
103     mkdir $OUTDIR
104     RETVAL=$?
105     if test "x$RETVAL" = x ; then
106     echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"
107 jmc 1.14 exit 3
108 edhill 1.1 fi
109 jmc 1.8 chgrp gcmpack $OUTDIR
110     chmod 775 $OUTDIR
111 edhill 1.1 fi
112    
113 jmc 1.10 all_files=`ls -1 $INDIR`
114 jmc 1.11 nb_files=`echo "$all_files" | grep -c '^msg\.'`
115 edhill 1.1
116 jmc 1.10 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 jmc 1.12 if test "x$ADDRERR" != x ; then
123     echo " (send msg to '$ADDRERR' if Error)"
124     fi
125 jmc 1.10 if test $PRT = 2 ; then echo -n " dir:" ; fi
126     fi
127 edhill 1.1
128     for file in $all_files ; do
129    
130     # create local copy
131 edhill 1.2 test -e $TEMPDIR && rm -rf $TEMPDIR
132 edhill 1.1 mkdir $TEMPDIR
133     cp $INDIR"/"$file $TEMPDIR
134    
135     # ignore multi-part messages
136     grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
137     RETVAL=$?
138     if test "x$RETVAL" = x0 ; then
139 jmc 1.12 if test "x$ADDRERR" != x ; then
140     echo "parsing email error" > tmp.$$
141     echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$
142     ls -l $INDIR"/"$file >> tmp.$$
143     mail -s 'parse_emails err_1' $ADDRERR < tmp.$$
144     rm -f tmp.$$
145     fi
146     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
147     continue
148 edhill 1.1 fi
149    
150     # munpack
151     mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
152     RETVAL=$?
153     if test "x$RETVAL" != x0 ; then
154 jmc 1.12 if test "x$ADDRERR" != x ; then
155     echo "parsing email error" > tmp.$$
156     echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$
157     ls -l $INDIR"/"$file >> tmp.$$
158     mail -s 'parse_emails err_2' $ADDRERR < tmp.$$
159     rm -f tmp.$$
160     fi
161     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
162     continue
163 edhill 1.1 fi
164    
165     # un-tar
166     ( cd $TEMPDIR ; tar -xzvf $mun > out )
167     RETVAL=$?
168     if test "x$RETVAL" != x0 ; then
169 jmc 1.12 if test "x$ADDRERR" != x ; then
170     echo "parsing email error" > tmp.$$
171     echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$
172     ls -l $INDIR"/"$file >> tmp.$$
173     ls -l $mun >> tmp.$$
174     mail -s 'parse_emails err_3' $ADDRERR < tmp.$$
175     rm -f tmp.$$
176     fi
177     mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file
178     continue
179 edhill 1.1 fi
180 edhill 1.2 tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1`
181 edhill 1.1 rm -f $TEMPDIR"/out"
182    
183     # copy to $OUTDIR and rename if necessary
184 jmc 1.10 sdir=$tdir
185 edhill 1.1 if test -e $OUTDIR"/"$tdir ; then
186     ad=0
187     while test -e $OUTDIR"/"$tdir"_"$ad ; do
188     ad=$(( $ad + 1 ))
189     done
190 jmc 1.10 sdir=$tdir"_"$ad
191 edhill 1.1 fi
192 jmc 1.10 if test $PRT = 2 ; then echo -n " '$sdir'" ; fi
193     mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1
194     chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1
195     # gzip $OUTDIR"/"$sdir"/output.txt"
196 edhill 1.1
197     # remove the original file
198     rm -f $INDIR"/"$file
199    
200     done
201 jmc 1.10 if test $PRT = 1 ; then echo " done" ; fi
202     if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi
203 edhill 1.1

  ViewVC Help
Powered by ViewVC 1.1.22