/[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.5 - (hide annotations) (download)
Mon Nov 28 13:34:31 2005 UTC (19 years, 7 months ago) by edhill
Branch: MAIN
Changes since 1.4: +17 -18 lines
 o speedup the script by doing things incrementally

1 edhill 1.1 #! /usr/bin/env bash
2    
3 edhill 1.5 # $Header: /u/gcmpack/mitgcm.org/front_content/parse_emails,v 1.4 2005/06/22 13:39:42 edhill 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     echo " (-help|-h) print usage"
17     echo " (-ind |-i )DIR get mpack-created emails from DIR"
18     echo " [def=\"$INDIR\"]"
19     echo " (-outd |-o )DIR write the data to DIR"
20     echo " [def=\"$OUTDIR\"]"
21     echo " (-tempd |-t )DIR use temporary directory DIR"
22     echo " [def=\"$TEMPDIR\"]"
23     echo
24     exit 1
25     }
26    
27     # defaults
28     INDIR="/u/edhill/Mail/MITgcm-test"
29     OUTDIR=
30     TEMPDIR=./ptmp
31 edhill 1.3 MUNPACK=/usr/local/bin/munpack
32 edhill 1.1
33     # Parse options
34     ac_prev=
35     for ac_option ; do
36    
37     # If the previous option needs an argument, assign it.
38     if test -n "$ac_prev"; then
39     eval "$ac_prev=\$ac_option"
40     ac_prev=
41     continue
42     fi
43    
44     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
45    
46     case $ac_option in
47    
48     -help | --help | -h | --h)
49     usage ;;
50    
51     -ind | --ind | -i | --i)
52     ac_prev=INDIR ;;
53     --ind=* | -ind=* | --i=* | -i=*)
54     INDIR=$ac_optarg ;;
55    
56     -outd | --outd | -o | --o)
57     ac_prev=OUTDIR ;;
58     --outd=* | -outd=* | --o=* | -o=*)
59     OUTDIR=$ac_optarg ;;
60    
61     -tempd | --tempd | -t | --t)
62     ac_prev=TEMPDIR ;;
63     --tempd=* | -tempd=* | --t=* | -t=*)
64     TEMPDIR=$ac_optarg ;;
65    
66     *)
67     # copy the file list to FL_#
68     echo "Error: don't understand argument \"$ac_option\""
69     usage
70     ;;
71    
72     esac
73    
74     done
75    
76     if test "x$OUTDIR" = x ; then
77     OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m`
78     fi
79     if test ! -e $OUTDIR ; then
80     mkdir $OUTDIR
81     RETVAL=$?
82     if test "x$RETVAL" = x ; then
83     echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created"
84     exit 1
85     fi
86     fi
87    
88     echo "Using OUTDIR=\"$OUTDIR\""
89     echo "Using INDIR=\"$INDIR\""
90    
91     all_files=`ls -1 $INDIR`
92    
93     echo -n "Unpacking the emails ..."
94     for file in $all_files ; do
95    
96     # create local copy
97 edhill 1.2 test -e $TEMPDIR && rm -rf $TEMPDIR
98 edhill 1.1 mkdir $TEMPDIR
99     cp $INDIR"/"$file $TEMPDIR
100    
101     # ignore multi-part messages
102     grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1
103     RETVAL=$?
104     if test "x$RETVAL" = x0 ; then
105     continue
106     fi
107    
108     # munpack
109     mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )`
110     RETVAL=$?
111     if test "x$RETVAL" != x0 ; then
112     continue
113     fi
114    
115     # un-tar
116     ( cd $TEMPDIR ; tar -xzvf $mun > out )
117     RETVAL=$?
118     if test "x$RETVAL" != x0 ; then
119     continue
120     fi
121 edhill 1.2 tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1`
122 edhill 1.1 rm -f $TEMPDIR"/out"
123    
124     # copy to $OUTDIR and rename if necessary
125     if test -e $OUTDIR"/"$tdir ; then
126     ad=0
127     while test -e $OUTDIR"/"$tdir"_"$ad ; do
128     ad=$(( $ad + 1 ))
129     done
130     mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad
131 edhill 1.5 chmod -R a+rx $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1
132     gzip $OUTDIR"/"$tdir"_"$ad"/output.txt"
133 edhill 1.1 else
134     mv $TEMPDIR"/"$tdir $OUTDIR
135 edhill 1.5 chmod -R a+rx $OUTDIR"/"$tdir > /dev/null 2>&1
136 edhill 1.1 gzip $OUTDIR"/"$tdir"/output.txt"
137     fi
138    
139     # remove the original file
140     rm -f $INDIR"/"$file
141    
142     done
143     echo " done"
144    
145 edhill 1.5 # echo -n "gzipping all the \"output.txt\" files ..."
146     # (
147     # cd $OUTDIR
148     # outp=`find . -name output.txt`
149     # if test "x$outp" != x ; then
150     # gzip $outp
151     # fi
152     # )
153     # echo " done"
154    
155     # echo -n "setting permissions to world-readable ..."
156     # chmod -R a+rx $OUTDIR > /dev/null 2>&1
157     # echo " done"
158 edhill 1.1
159    

  ViewVC Help
Powered by ViewVC 1.1.22