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