--- mitgcm.org/front_content/parse_emails 2006/10/12 01:51:09 1.7 +++ mitgcm.org/front_content/parse_emails 2008/03/19 00:55:28 1.17 @@ -1,6 +1,6 @@ #! /usr/bin/env bash -# $Header: /home/ubuntu/mnt/e9_copy/mitgcm.org/front_content/parse_emails,v 1.7 2006/10/12 01:51:09 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/mitgcm.org/front_content/parse_emails,v 1.17 2008/03/19 00:55:28 jmc Exp $ # # The purpose of this script is to parse the emails produced by the # MITgcm/verificaton/testreport script and store the data in a @@ -13,22 +13,30 @@ echo "Usage: $0 [OPTIONS]" echo echo "where possible OPTIONS are:" - echo " (-help|-h) print usage" - echo " (-ind |-i )DIR get mpack-created emails from DIR" + echo " (-h|-help) print usage" + echo " (-s|-silent) silent mode" + echo " (-v|-verbose) verbose mode" + echo " (-i |-ind )DIR get mpack-created emails from DIR" echo " [def=\"$INDIR\"]" - echo " (-outd |-o )DIR write the data to DIR" + echo " (-o |-outd )DIR write the data to DIR" echo " [def=\"$OUTDIR\"]" - echo " (-tempd |-t )DIR use temporary directory DIR" + echo " (-t |-tempd )DIR use temporary directory DIR" echo " [def=\"$TEMPDIR\"]" + echo " (-u |-unpack )EXE use executable EXE to unpack e-mails" + echo " [def=\"$MUNPACK\"]" + echo " (-a |-addr )ADDR send e-mail to ADDR if Error" + echo " [def='"$ADDRERR"']" echo exit 1 } # defaults -INDIR="/u/edhill/Mail/MITgcm-test" -OUTDIR= +INDIR="/u/u2/jmc/Mail/MITgcm-test" +OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` TEMPDIR=./ptmp -MUNPACK=/u/edhill/local/bin/munpack +MUNPACK=munpack +ADDRERR= +PRT=1 # Parse options ac_prev= @@ -47,6 +55,10 @@ -help | --help | -h | --h) usage ;; + -s | --s | -silent | --silent) + PRT=0 ;; + -v | --v | -verbose | --verbose) + PRT=2 ;; -ind | --ind | -i | --i) ac_prev=INDIR ;; @@ -62,7 +74,17 @@ ac_prev=TEMPDIR ;; --tempd=* | -tempd=* | --t=* | -t=*) TEMPDIR=$ac_optarg ;; + + -u | --u | -unpack | --unpack) + ac_prev=MUNPACK ;; + -u=* | --u=* | -unpack=* | --unpack=*) + MUNPACK=$ac_optarg ;; + -a | --a | -addr | --addr) + ac_prev=ADDRERR ;; + -a=* | --a=* | -addr=* | --addr=*) + ADDRERR=$ac_optarg ;; + *) # copy the file list to FL_# echo "Error: don't understand argument \"$ac_option\"" @@ -73,87 +95,138 @@ done -if test "x$OUTDIR" = x ; then - OUTDIR="/u/u0/httpd/html/testing/results/"`date +%Y`"_"`date +%m` +if test ! -x $MUNPACK ; then + echo "ERROR: \"$MUNPACK\" is not executable" + exit 2 fi if test ! -e $OUTDIR ; then mkdir $OUTDIR RETVAL=$? - if test "x$RETVAL" = x ; then + if test "x$RETVAL" != x0 ; then echo "ERROR: directory \"$OUTDIR\" doesn't exist and can't be created" - exit 1 + exit 3 fi + chgrp gcmpack $OUTDIR + chmod 775 $OUTDIR fi -echo "Using OUTDIR=\"$OUTDIR\"" -echo "Using INDIR=\"$INDIR\"" - all_files=`ls -1 $INDIR` +nb_files=`echo "$all_files" | grep -c '^msg\.'` + +if test $PRT = 1 ; then + echo "Using OUTDIR=\"$OUTDIR\"" + echo "Using INDIR=\"$INDIR\"" + echo -n "Unpacking the emails ..." +elif test $nb_files != 0 ; then + echo -n "Unpacking $nb_files emails ("`date` + if test "x$ADDRERR" != x ; then + echo -n ", err-msg: '$ADDRERR'" + fi + echo ")" + echo " from '$INDIR' to '$OUTDIR'" +fi -echo -n "Unpacking the emails ..." for file in $all_files ; do # create local copy test -e $TEMPDIR && rm -rf $TEMPDIR mkdir $TEMPDIR - cp $INDIR"/"$file $TEMPDIR + RETVAL=$? + if test "x$RETVAL" = x0 ; then + cp $INDIR"/"$file $TEMPDIR + RETVAL=$? + fi + if test "x$RETVAL" != x0 ; then + if test "x$ADDRERR" != x ; then + echo "parsing email error" > tmp.$$ + echo " processing file: '$INDIR/$file'" >> tmp.$$ + echo -n "'mkdir $TEMPDIR' or 'cp $INDIR/$file $TEMPDIR'" >> tmp.$$ + echo " returns error $RETVAL" >> tmp.$$ + mail -s 'parse_emails err_0' $ADDRERR < tmp.$$ + rm -f tmp.$$ + fi + mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file + continue + fi # ignore multi-part messages grep "Content-Type: message/partial" $INDIR"/"$file > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then - continue + if test "x$ADDRERR" != x ; then + echo "parsing email error" > tmp.$$ + echo 'grep "Content-Type: message/partial" returns error:' $RETVAL >> tmp.$$ + ls -l $INDIR"/"$file >> tmp.$$ + mail -s 'parse_emails err_1' $ADDRERR < tmp.$$ + rm -f tmp.$$ + fi + mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file + continue fi # munpack mun=`( cd $TEMPDIR ; $MUNPACK $file | cut -d ' ' -f 1 | head -1 )` RETVAL=$? if test "x$RETVAL" != x0 ; then - continue + if test "x$ADDRERR" != x ; then + echo "parsing email error" > tmp.$$ + echo "$MUNPACK $file returns error: $RETVAL" >> tmp.$$ + ls -l $INDIR"/"$file >> tmp.$$ + mail -s 'parse_emails err_2' $ADDRERR < tmp.$$ + rm -f tmp.$$ + fi + mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file + continue fi # un-tar ( cd $TEMPDIR ; tar -xzvf $mun > out ) RETVAL=$? if test "x$RETVAL" != x0 ; then - continue + if test "x$ADDRERR" != x ; then + echo "parsing email error" > tmp.$$ + echo "tar -xzvf $mun returns error:" $RETVAL >> tmp.$$ + ls -l $INDIR"/"$file >> tmp.$$ + ls -l $mun >> tmp.$$ + mail -s 'parse_emails err_3' $ADDRERR < tmp.$$ + rm -f tmp.$$ + fi + mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file + continue fi tdir=`cat $TEMPDIR"/out" | head -1 | sed -e 's|^./||g' | cut -d '/' -f 1` rm -f $TEMPDIR"/out" # copy to $OUTDIR and rename if necessary + sdir=$tdir if test -e $OUTDIR"/"$tdir ; then ad=0 while test -e $OUTDIR"/"$tdir"_"$ad ; do ad=$(( $ad + 1 )) done - mv $TEMPDIR"/"$tdir $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1 - chmod -R a+rx $OUTDIR"/"$tdir"_"$ad > /dev/null 2>&1 - gzip $OUTDIR"/"$tdir"_"$ad"/output.txt" - else - mv $TEMPDIR"/"$tdir $OUTDIR > /dev/null 2>&1 - chmod -R a+rx $OUTDIR"/"$tdir > /dev/null 2>&1 - gzip $OUTDIR"/"$tdir"/output.txt" + sdir=$tdir"_"$ad + fi + if test $PRT = 2 ; then echo " '$sdir'" ; fi + mv $TEMPDIR"/"$tdir $OUTDIR"/"$sdir > /dev/null 2>&1 + RETVAL=$? + if test "x$RETVAL" != x0 ; then + if test "x$ADDRERR" != x ; then + echo "parsing email error" > tmp.$$ + echo "mv $TEMPDIR/$tdir $OUTDIR/$sdir returns error:" $RETVAL >> tmp.$$ + echo -n "in dir: $TEMPDIR : " ; ls -l $TEMPDIR >> tmp.$$ + echo -n "in dir: $OUTDIR : " ; ls -l $OUTDIR >> tmp.$$ + mail -s 'parse_emails err_4' $ADDRERR < tmp.$$ + rm -f tmp.$$ + fi + mv -f $INDIR"/"$file $INDIR"/../fail2process/"$file + continue fi + chmod -R a+rx $OUTDIR"/"$sdir > /dev/null 2>&1 +# gzip $OUTDIR"/"$sdir"/output.txt" # remove the original file rm -f $INDIR"/"$file done -echo " done" - -# echo -n "gzipping all the \"output.txt\" files ..." -# ( -# cd $OUTDIR -# outp=`find . -name output.txt` -# if test "x$outp" != x ; then -# gzip $outp -# fi -# ) -# echo " done" - -# echo -n "setting permissions to world-readable ..." -# chmod -R a+rx $OUTDIR > /dev/null 2>&1 -# echo " done" - +if test $PRT = 1 ; then echo " done" ; fi