[ 15 January 1998
  The Linux Print2Win mini-HOWTO is not being maintained by 
  the author any more.  If you are interested in maintaining the 
  Print2Win mini-HOWTO, please get in touch with me at 
  <tjbynum@metalab.unc.edu>. ]

   
     _________________________________________________________________
   
      This page was last updated on June 7th 1996.
      
    A SIMPLE HOW-TO PRINT FROM LINUX TO A WINDOWS 95/WINDOWS NT PRINT SHARE
                                       
   My setup:
     * Latest kernel (pre-2.0.12)
     * SAMBA
     * Standard lpr utilities
     * Two printers - LexMark Optra C PS (colour) and LexMark Optra R+ PS
       (black and white)
       
   I have two ways to print to my printers: _
     * first is via the standard lpr command
     * second via SAMBA's smbclient print option
       
   They both use the /etc/printcap file which reproduced below.
   

/etc/printcap:
#
# Set the environment variable PRINTER to either
# PRINTER=eng or PRINTER=colour or PRINTER=optrac or PRINTER=optrar
# if you want to use the lpr command by itself.  Alternatively, you
# can say lpr -P to print your file.
#                               Harish Pillay (h.pillay@ieee.org)
# //gaia/lexENG1 via smbprint
#
eng|lp:\
        :cm=LexMark Optra R+ PostScript Printer:\
        :lp=/dev/eng:\
        :sd=/var/spool/lpd/eng:\
        :af=/var/spool/lpd/eng/acct:\
        :mx#0:\
        :if=/usr/local/samba/bin/smbprint:
#
# //gaia/lexTRG1 via smbprint
#
colour|lpcolour:\
        :cm=LexMark Optra C PostScript Printer:\
        :lp=/dev/colour:\
        :sd=/var/spool/lpd/colour:\
        :af=/var/spool/lpd/colour/acct:\
        :mx#0:\
        :if=/usr/local/samba/bin/smbprint:
#
# using lpr directly to Optra R+ Postscript (B&W)
#
optrar:\
        :cm=LexMark Optra R+ PostScript Printer:\
        :sd=/usr/spool/lpd:\
        :lf=/usr/spool/lpd/errors:\
        :rp=optrar.dom.ain:\
        :rm=optrar.dom.ain:\
        :sh:\
        :sf:
#
# using lpr directly to Optra C Postscript (Colour)
#
optrac:\
        :cm=LexMark Optra C PostScript Printer:\
        :sd=/usr/spool/lpd:\
        :lf=/usr/spool/lpd/errors:\
        :rp=optrac.dom.ain:\
        :rm=optrac.dom.ain:\
        :sh:\
        :sf:

#end of /etc/printcap file

   Steps:
     * Fire up lpd (check /etc/rc.d/rc.M and /etc/rc.d/rc.inet2).
     * If you are using straightforward lpr (meaning that the printer
       itself *knows* how to talk lpd), then you can go directly using
       lpr to print.
     * If your printer cannot talk lpd and you are going via your Windows
       95 or Windows NT printer share option, you need to use SAMBA.
     * After making sure SAMBA works on your machine, use the smbprint
       (in the SAMBA distribution) script to do the printing
       (http://www.nijenrode.nl/~steven/ldp/Printing-HOWTO.html).
       
   Here's my copy of the smbprint script modified slightly:
   
   /usr/local/samba/bin/smbprint:

#!/bin/sh -x

# This script is an input filter for printcap printing on a unix machine. It
# uses the smbclient program to print the file to the specified smb-based
# server and service.
# For example you could have a printcap entry like this
#
# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
#
# which would create a unix printer called "smb" that will print via this
# script. You will need to create the spool directory /usr/spool/smb with
# appropriate permissions and ownerships for your system.
#
# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton)
# so that the server, service, and password can be read from
# a /usr/var/spool/lpd/PRINTNAME/.config file.
#
# Script further modified to add user variable by h.pillay@ieee.org (Harish Pil
lay)
#
# In order for this to work the /etc/printcap entry must include an
# accounting file (af=...):
#
#   cdcolour:\
#       :cm=CD IBM Colorjet on 6th:\
#       :sd=/var/spool/lpd/cdcolour:\
#       :af=/var/spool/lpd/cdcolour/acct:\
#       :if=/usr/local/etc/smbprint:\
#       :mx=0:\
#       :lp=/dev/null:
#
# The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
#   server=PC_SERVER
#   service=PR_SHARENAME
#   password="password"
#   user=USERNAME          (added by h.pillay@ieee.org)
#
# E.g.
#   server=PAULS_PC
#   service=CJET_371
#   password=""
#   user=HARISH          (added by h.pillay@ieee.org)

#
# Debugging log file, change to /dev/null if you like.
#
logfile=/tmp/smb-print.log
# logfile=/dev/null


#
# The last parameter to the filter is the accounting file name.
#   Extract the directory name from the file name.
#   Concat this with /.config to get the config file.
#
eval acct_file=\$$#
spool_dir=`dirname $acct_file`
config_file=$spool_dir/.config

# Should read the following variables set in the config file:
#   server
#   service
#   password
#   user               (added by h.pillay@ieee.org)
eval `cat $config_file`

#
# Some debugging help, change the >> to > if you want to same space.
#
echo "server $server, service $service" >> $logfile

(
# NOTE You may wish to add the line `echo translate' if you want automatic
# CR/LF translation when printing.
        echo translate
        echo "print -"
        cat
) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $user -
N -P >> $logfile

#end of /usr/local/samba/bin/smbprint

   
     _________________________________________________________________
   
   Hint from Rick Bressler :

Good tip sheet.  I use something very similar.  One helpful tip, this is not
a particularly good idea:

        :lp=/dev/null:\

lpr does an 'exclusive' open on the file you specify as lp=.  It does this in
order to prevent multiple processes from trying to print to the dame printer
at the same time.

The side effect of this is that in your case, eng and colour can't print at
the same time, (usually more or less transparent since they probably print
quickly and since they queue you probably don't notice) but any other process
that tries to write to /dev/null will break!

On a single user system, probably not a big problem.  I have a system with
over 50 printers.  It would be a problem there.

The solution is to create a dummy printer for each.  Eg: touch /dev/eng.

   I have modified the lp entries in the printcap file above to take into
   account Rick's suggestion. I did the following:
   

#touch /dev/eng
#touch /dev/colour

   Thanks Rick for the tip from the battlefield!
   
   
     _________________________________________________________________
   
                                SUCCESS STORY:
                                       
   What completely amazed me is how the printcap worked for both ways of
   printing, lpr directly and lpr via smbprint. And, to top it all, how
   the colour printing worked the first time round! Kudos to the ace
   programmers!
     _________________________________________________________________
   
   Questions? Email me.
   
   Go back to Harish's Home Page
     _________________________________________________________________
