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

Contents of /mitgcm.org/front_content/parse_emails

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


Revision 1.11 - (show annotations) (download)
Sat Dec 1 18:55:13 2007 UTC (17 years, 7 months ago) by jmc
Branch: MAIN
Changes since 1.10: +2 -2 lines
fix message counting

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

  ViewVC Help
Powered by ViewVC 1.1.22