/[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.11 - (hide 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 edhill 1.1 #! /usr/bin/env bash
2    
3 jmc 1.11 # $Header: /u/gcmpack/mitgcm.org/front_content/parse_emails,v 1.10 2007/11/30 17:14:43 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     echo
26     exit 1
27     }
28    
29     # defaults
30     INDIR="/u/edhill/Mail/MITgcm-test"
31     OUTDIR=
32     TEMPDIR=./ptmp
33 edhill 1.7 MUNPACK=/u/edhill/local/bin/munpack
34 jmc 1.10 PRT=1
35 edhill 1.1
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 jmc 1.10 -s | --s | -silent | --silent)
54     PRT=0 ;;
55     -v | --v | -verbose | --verbose)
56     PRT=2 ;;
57 edhill 1.1
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 jmc 1.8 chgrp gcmpack $OUTDIR
94     chmod 775 $OUTDIR
95 edhill 1.1 fi
96    
97 jmc 1.10 all_files=`ls -1 $INDIR`
98 jmc 1.11 nb_files=`echo "$all_files" | grep -c '^msg\.'`
99 edhill 1.1
100 jmc 1.10 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 edhill 1.1
109     for file in $all_files ; do
110    
111     # create local copy
112 edhill 1.2 test -e $TEMPDIR && rm -rf $TEMPDIR
113 edhill 1.1 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 edhill 1.2 tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1`
137 edhill 1.1 rm -f $TEMPDIR"/out"
138    
139     # copy to $OUTDIR and rename if necessary
140 jmc 1.10 sdir=$tdir
141 edhill 1.1 if test -e $OUTDIR"/"$tdir ; then
142     ad=0
143     while test -e $OUTDIR"/"$tdir"_"$ad ; do
144     ad=$(( $ad + 1 ))
145     done
146 jmc 1.10 sdir=$tdir"_"$ad
147 edhill 1.1 fi
148 jmc 1.10 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 edhill 1.1
153     # remove the original file
154     rm -f $INDIR"/"$file
155    
156     done
157 jmc 1.10 if test $PRT = 1 ; then echo " done" ; fi
158     if test $PRT = 2 -a $nb_files != 0 ; then echo "" ; fi
159 edhill 1.1
160 edhill 1.5 # 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"
173 edhill 1.1
174    

  ViewVC Help
Powered by ViewVC 1.1.22