Sambafax

SENDMAIL="/usr/sbin/sendmail" PS2ASCII="/usr/bin/ps2ascii" AWK="/bin/awk" SENDFAX="/usr/bin/sendfax" FAXFILE=/tmp/sambafax.$$ while : do case "$1" in       -n) Username="$2"            shift ; shift            ;;        -h) Hostname="$2" shift ; shift ;;      -*)  shift            ;;        *) break esac done if [ "$Username" = "nobody" ]; then MailTo="postmaster" else MailTo=${Username} fi cat >${FAXFILE}
 * 1) !/bin/sh
 * 2) constants
 * 1) make up a temporary file
 * 1) retrieve the username and hostname from the paramaters
 * 1) if the samba user is anonumous then send mails to the postmaster
 * 1) now dump the to-be faxewd data (PS fdormat) to the temp file

FAXNUM=`${PS2ASCII} ${FAXFILE} | ${AWK} '{ IGNORECASE=1 } /FAX-Nr ?: ?[0-9-]*/ \ { $0=$0 "xxx"; \ gsub(/-/,""); \ anfang=match($0,/ ?: ?/); \ anfang=anfang+match(substr($0,anfang),/[0-9]/)-1; \ ende=match(substr($0,anfang),/[^0-9]/)-1; \ printf ("%s",substr($0,anfang,ende)) \ }' ` if [ -z ${FAXNUM} ] ; then (echo "To: ${MailTo}"    echo "From: The HylaFAX Samba dancer "     echo "Subject: your facsimile request failed"     echo ""     echo "The faxnumber is not recognized in your fax of"     echo `date`     echo ""     echo "The faxnumber is recognised via this text:"     echo "   Fax-Nr : ddd-ddddddd"     echo "No spaces or characters are allowed between the digits, just a -"     echo ""     echo "Please correct and retry"    ) | 2>&1 ${SENDMAIL} -ffax -oi ${MailTo} else ${SENDFAX} -n -D -f ${MailTo} -d ${FAXNUM} ${FAXFILE} fi rm -f ${FAXFILE}
 * 1) retrieve the faxnumber from the printfile
 * 2) the silly three x's are added because some awk strugle with an immediate CR
 * 3) we use a PS to ascii pipe to strip (most of) the Postscript controls
 * 1) if faxnumber is found fax the tempfile
 * 2) we donot check the validity of the faxnumber, let sendfax do this...
 * 1) remove the temp file
 * 1) end of show