As400pscript


 * 1) !/bin/sh

cat - > /tmp/as.$$

Username="$1"

FILE_AS400=/tmp/as1.$$ FILE_T=/tmp/as2.$$ FILE_PS=/tmp/ps.$$

SENDMAIL="/usr/sbin/sendmail"
 * 1) TIFFBIN="/usr/bin"		  |
 * 2) MIMENCODE=/usr/bin/mimencode   |
 * 3) PS2PDF=$TIFFBIN/ps2pdf < For email notifications with the file,in PDF format
 * 4) 					  |attached.


 * 1) At the beginning I thought that will be important to check if thefile exists,
 * 2) but I realise that the file will never fail. But the line remains here, if later
 * 3) proves to be necessary.
 * 4) if [ -s /tmp/as.$$ ] ; then
 * 1) if [ -s /tmp/as.$$ ] ; then

LANG=en_US col -b < /tmp/as.$$ > $FILE_AS400
 * 1) Here is where we merge the text from AS400 with the company logo,
 * 2) stored in a file in ENCAPSULATED POSTSCRIPT format. Pay attention,
 * 3) in EPS format! This is very important to work correctly.
 * 4) Some tricks are made to work here so, if not work for you just
 * 5) ask. Thanks goes for Giulio Orsero for is asistance.

echo -e "\000epsf[x0ca y0ca nx ny ]{COMPANYLOGO.eps}" > $FILE_T

cat $FILE_AS400 >> $FILE_T

/usr/bin/enscript -B -e $FILE_T -p $FILE_PS

UNAME=`echo "$Username" | sed -ne '/'-A'/{s/^.*'-A'//g;s/@.*//g;p;q;}' | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
 * 1) Our users login in AS400 are in uppercase and to not duplicate
 * 2) entrys I change them to lowercase


 * 1) Fax number extracted from the text. The text should have an entry
 * 2) like Fax : 1234567, not Fax: 1234567 or similar.

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

if [ "$FAXNUMBER" = "" ] ; then

(MIMEBOUNDARY="NextPart$$"    echo "Mime-Version: 1.0"     echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\""     echo "Content-Transfer-Encoding: 7bit"     echo "To: $UNAME@yourhost"     echo "From: Fax Server "     echo "Subject: Outgoing fax job failure"     echo ""     echo "--$MIMEBOUNDARY";     echo ""     echo "You request could not be completed!"     echo `date`     echo ""     echo ""     echo "Please, check if the fax number is missing openning the file attached."     echo ""     echo "--$MIMEBOUNDARY";     echo "Content-Type: application/postscript; name=$FNAME";     echo "Content-Description: FAX document;";     echo "Content-Disposition: inline;";     echo "Content-Transfer-Encoding: 7bit";     echo "";     cat $FILE_PS     echo "";     echo "--$MIMEBOUNDARY--";     echo "";   ) | 2>&1 $SENDMAIL -ffax -oi $UNAME@yourhost

else

sendfax -n -D -f $UNAME@yourhost -d $FAXNUMBER $FILE_PS

fi

rm -f /tmp/as.$$ $FILE_AS400 $FILE_T $FILE_PS