#!/bin/bash # Captures the spool File # Don't forget to change the domain names to ones that will for you, since these won't! cat - > /tmp/as.$$ # Declare Variable # Paths to temporary files FILE_PDF=/tmp/as4$$.pdf FILE_AS400=/tmp/as.$$ FILE_PS=/tmp/ps.$$ # Path to e-mail server program SENDMAIL="/usr/sbin/sendmail" MIMENCODE=mimencode # Variable defaults UNAME=QUSER #IBM Defaults I chose to use while testing FNAME=OTHER #IBM Defaults I chose to use while testing COMMENT='Please Contact Sender if any Pages are Missing.' # Default Comment for the cover page # Pedro's original script did not work for me, so I used getopt to capture the options passed from LPRng to the "printer" # Go to the LPRng website to find out what all the letters mean, or uncomment the ECHO $TEMP2 line in the e-mail body # Grabs all of the options, you need to uncomment this to see all of the data passed # TEMP2=`getopt -o A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:T:S:U:V:W:X:Y:Z:a:b:cd:e:f:g:h:i:j:k:l: m:n:o:p:q:r:t:s:u:v:w:x:y:z \ -- "$@"` # Grabs only the options I wanted, username without domain and the document type TEMP=`getopt -a -o N:n: -- "$@"` eval set -- "$TEMP" while true ; do case "$1" in -n) USER="$2"; shift 2 ;; -N) FNAME="$2"; shift 2 ;; *) shift; break ;; esac done # I Inherited this as400 and was not willing to setup the rest of the network using the same user name scheme # The case statement is how I corrected this, I also put user specifc comments here. case "$USER" in ROB) UNAME=rsherman ;; JACKIE) UNAME=jmoore ; COMMENT='Please be Aware that the following Invoice(s) were processed today towards your account and payment will be due upon agreed terms.';; *) UNAME=$USER ;; esac # Here is where the spool file is converted to PostScript and the # Header with the same name as stored in the variable field # $FNAME is applied. Please look at the ACKFORM example before attempting # to create a header file /usr/bin/enscript --fancy-header=$FNAME $FILE_AS400 -p $FILE_PS # Where you pick the faxnumber FAXNUMBER=`sed -ne '/'Fax'/{s/^.*'Fax' : *//g;s/[()]//g;s/[^0-9]\{1,\}.*^M$//g;p;q;}'` < /tmp/as.$$ # Converts the Postscript file to pdf in preparation of e-mailing it back to the user ps2pdf $FILE_PS $FILE_PDF # Begining of the e-mail structure (MIMEBOUNDARY="NextPart$$" echo "Mime-Version: 1.0" echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\"" echo "Content-Transfer-Encoding: 7bit" echo "To: $UNAME@yourhost.yourdomain" echo "From: Fax Server" echo "Subject: Outgoing fax job to $FAXNUMBER submitted" echo "" echo "--$MIMEBOUNDARY"; echo "" echo `date` echo "" echo "Your request has been queued for delivery." echo "There will be an E-Mail confirming delivery of your" echo "fax to $FAXNUMBER." echo "" echo "" echo "If you do not receive a confirmation in one hour, notify the system administrator." echo "Attached is a PDF File containing the contents of your fax." echo "" # echo "$TEMP2" # uncomment this line to see all of the LPRng options passed echo "--$MIMEBOUNDARY"; echo "Content-Type: application/pdf; name=\"$FNAME.pdf\"" echo "Content-Description: FAX document" echo "Content-Transfer-Encoding: base64" echo "Content-Disposition: attachment; filename=\"$FNAME.pdf\"" echo "Content-Description: FAX document" echo "Content-Transfer-Encoding: base64" echo "Content-Disposition: attachment; filename=\"$FNAME.pdf\"" echo "" #Embeds the PDF in the e-mail and removes it from the temp directory $MIMENCODE $FILE_PDF 2>/dev/null $RM -f $FILE_PDF 2>/dev/null echo ""; echo "--$MIMEBOUNDARY--"; echo ""; ) | 2>&1 $SENDMAIL -ffax -oi $UNAME@yourhost.yourdomain # If there is no fax number this keeps the script from hanging or worse if [ "$FAXNUMBER" = "" ] ; then echo $UNAME else # I have the fax being submitted with the default cover page and the comments section being passed through sendfax -D -R -f $UNAME@yourhost.yourdomain -c "$COMMENT" -d $FAXNUMBER $FILE_PS fi # Cleaning up after myself again rm -f /tmp/as.$$ $FILE_PDF $FILE_PS