#!/bin/bash

# this script allows the caller to send a (possibly) 
# user defined message signifying an important autobench event
# Use message must be enclosed in double quotes if multiple words.
# ex: notify foo@bar.com  "I am done"


. /etc/autobench.conf || . functions

if [ $# -lt 1 -o $# -gt 2 ]
then
  log "notify takes two arguments, an email address and an optional subject line"
  exit
fi

ADDRESS=$1
FROM=$(hostname -s)
TEXT=$(tail -n 50 $AUTODIR/logs/logfile)

if [ $# -eq 1 ]
then
  SUBJECT="autobench notify service on $FROM"
else
  SUBJECT=$2
fi

echo "$TEXT" | mail -s "$SUBJECT" $ADDRESS
