#!/bin/sh
#
# Script which concatenates email from cfengine
# avoiding repetetive messages
#
# MB 23/7/97
#
#

PATH=/usr/bin:/bin:/sbin ; export PATH

tmpfile=/tmp/new-mail-from-cfengine
cftmpdir=/tmp

cat > $tmpfile

machineline=`grep Subject: $tmpfile`
machine=`echo $machineline | sed s/[\ -/]/_/g | cut -d: -f2`

touch $cftmpdir/$machine
egrep '^cfengine:.*' $tmpfile > $cftmpdir/$machine.new

if test `diff $cftmpdir/$machine.new $cftmpdir/$machine | wc -l` -ne 0; then

 mv $cftmpdir/$machine.new $cftmpdir/$machine

 #
 # This next piece could be replaced by a cgi script to show the results
 #

 ( echo "$machineline"; echo "" ; cat $cftmpdir/$machine ) | mail mark@iu.hioslo.no

fi
