View Single Post
  #4   (View Single Post)  
Old 12th October 2009
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

@J65nko

I used my script for that:

Code:
#! /bin/sh

# subject
SUBJ="$( hostname -s ) | $( basename ${0} ) | report"

__usage() {
  echo "usage: $( basename ${0} ) email@domain.com message.txt [file1] [file2]"
  exit 1
}

__check_file() {
  if [ ! -f "${1}" ]
  then
    echo "error: file '${1}' does not exist"
    exit 1
  fi
}

__check_mail() {
  if [ ${?} -ne 0 ]
  then
    echo "error: mail(1) failed to send message"
    exit 1
  fi
}

[ ! ${#} -ge 2 ] && __usage
__check_file "${2}"

MAIL="${1}"
MESG="${2}"

case ${#} in 
  (2)
    mail -s "${SUBJ}" "${MAIL}" < "${MESG}"
    __check_mail
    ;;

  (*)
    shift
    shift
    BODY="$( basename ${0} ).body"

    cat "${MESG}" > "${BODY}"
    for FILE in "${@}"
    do
      __check_file "${FILE}"
      uuencode "${FILE}" "${FILE}" >> "${BODY}"
    done
    mail -s "${SUBJ}" "${MAIL}" < "${BODY}" 
    __check_mail
    ;;

esac
Of course it can be extended to support subject/cc/bcc ... but nice to know other alternatives as matts.
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote