#! /bin/bash -
#
#  H.A.Trujillo, 1 May 2011
 
if [ "x$1" == "x-h" ]; then cat << EOT
 
  a wrapper-script to pipe output from another script or a command
  into a mail message.
 
     Usage:	rapporteur command [arguments-to-command]
 
 	     	    eg: rapporteur ls -l myfile
 
     Rationale:	back in the old days, cron mailed users its output,
 		but launchd no longer does. 
 
EOT
exit
fi


MAIL_TO=${USER:=root}@localhost
TMPFILE=`mktemp /tmp/rapporteur.${USER}.XXXXXX`

$* > $TMPFILE  2>&1
ExitStatus=$?

mail -E -s "launchd output -- ${1##/*/}" $MAIL_TO < $TMPFILE
sleep 3
rm $TMPFILE


exit $ExitStatus

