As400script2


 * 1) !/bin/bash

cat - > /tmp/as.$$
 * 1) Captures the spool File
 * 2) Don't forget to change the domain names to ones that will for you, since these won't!

FILE_PDF=/tmp/as4$$.pdf FILE_AS400=/tmp/as.$$ FILE_PS=/tmp/ps.$$
 * 1) Declare Variable
 * 2) Paths to temporary files

SENDMAIL="/usr/sbin/sendmail" MIMENCODE=mimencode
 * 1) Path to e-mail server program

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
 * 1) Variable defaults


 * 1) Pedro's original script did not work for me, so I used getopt to capture the options passed from LPRng to the "printer"
 * 2) Go to the LPRng website to find out what all the letters mean, or uncomment the ECHO $TEMP2 line in the e-mail body

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 \ -- "$@"` 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
 * 1) Grabs all of the options, you need to uncomment this to see all of the data passed
 * 2) TEMP2=`getopt -o
 * 1) Grabs only the options I wanted, username without domain and the document type

network using the same user name scheme comments here.
 * 1) I Inherited this as400 and was not willing to setup the rest of the
 * 1) The case statement is how I corrected this, I also put user specifc

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

/usr/bin/enscript --fancy-header=$FNAME $FILE_AS400 -p $FILE_PS
 * 1) Here is where the spool file is converted to PostScript and the
 * 2) Header with the same name as stored in the variable field
 * 3) $FNAME is applied.  Please look at the ACKFORM example before attempting
 * 4) to create a header file

FAXNUMBER=`sed -ne '/'Fax'/{s/^.*'Fax' : *//g;s/[]//g;s/[^0-9]\{1,\}.*^M$//g;p;q;}'` < /tmp/as.$$
 * 1) Where you pick the faxnumber

ps2pdf $FILE_PS $FILE_PDF
 * 1) Converts the Postscript file to pdf in preparation of e-mailing it back to the user

(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 "" 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 ""
 * 1) Begining of the e-mail structure
 * 1) 	 echo	"$TEMP2" # uncomment this line to see all of the LPRng options
 * 1) 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 [ "$FAXNUMBER" = "" ] ; then echo    $UNAME else
 * 1) If there is no fax number this keeps the script from hanging or worse

sendfax -D -R -f $UNAME@yourhost.yourdomain -c "$COMMENT" -d $FAXNUMBER  $FILE_PS fi
 * 1) I have the fax being submitted with the default cover page and the comments section being passed through

rm -f /tmp/as.$$ $FILE_PDF $FILE_PS
 * 1) Cleaning up after myself again