home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 August / PCWorld_1999-08_cd.bin / doc / HOWTO / unmaintained / mini / Print2Win < prev    next >
Text File  |  1998-01-14  |  7KB  |  224 lines

  1. [ 15 January 1998
  2.   The Linux Print2Win mini-HOWTO is not being maintained by 
  3.   the author any more.  If you are interested in maintaining the 
  4.   Print2Win mini-HOWTO, please get in touch with me at 
  5.   <gregh@sunsite.unc.edu>. ]
  6.  
  7.    
  8.      _________________________________________________________________
  9.    
  10.       This page was last updated on June 7th 1996.
  11.       
  12.     A SIMPLE HOW-TO PRINT FROM LINUX TO A WINDOWS 95/WINDOWS NT PRINT SHARE
  13.                                        
  14.    My setup:
  15.      * Latest kernel (pre-2.0.12)
  16.      * SAMBA
  17.      * Standard lpr utilities
  18.      * Two printers - LexMark Optra C PS (colour) and LexMark Optra R+ PS
  19.        (black and white)
  20.        
  21.    I have two ways to print to my printers: _
  22.      * first is via the standard lpr command
  23.      * second via SAMBA's smbclient print option
  24.        
  25.    They both use the /etc/printcap file which reproduced below.
  26.    
  27.  
  28. /etc/printcap:
  29. #
  30. # Set the environment variable PRINTER to either
  31. # PRINTER=eng or PRINTER=colour or PRINTER=optrac or PRINTER=optrar
  32. # if you want to use the lpr command by itself.  Alternatively, you
  33. # can say lpr -P to print your file.
  34. #                               Harish Pillay (h.pillay@ieee.org)
  35. # //gaia/lexENG1 via smbprint
  36. #
  37. eng|lp:\
  38.         :cm=LexMark Optra R+ PostScript Printer:\
  39.         :lp=/dev/eng:\
  40.         :sd=/var/spool/lpd/eng:\
  41.         :af=/var/spool/lpd/eng/acct:\
  42.         :mx#0:\
  43.         :if=/usr/local/samba/bin/smbprint:
  44. #
  45. # //gaia/lexTRG1 via smbprint
  46. #
  47. colour|lpcolour:\
  48.         :cm=LexMark Optra C PostScript Printer:\
  49.         :lp=/dev/colour:\
  50.         :sd=/var/spool/lpd/colour:\
  51.         :af=/var/spool/lpd/colour/acct:\
  52.         :mx#0:\
  53.         :if=/usr/local/samba/bin/smbprint:
  54. #
  55. # using lpr directly to Optra R+ Postscript (B&W)
  56. #
  57. optrar:\
  58.         :cm=LexMark Optra R+ PostScript Printer:\
  59.         :sd=/usr/spool/lpd:\
  60.         :lf=/usr/spool/lpd/errors:\
  61.         :rp=optrar.dom.ain:\
  62.         :rm=optrar.dom.ain:\
  63.         :sh:\
  64.         :sf:
  65. #
  66. # using lpr directly to Optra C Postscript (Colour)
  67. #
  68. optrac:\
  69.         :cm=LexMark Optra C PostScript Printer:\
  70.         :sd=/usr/spool/lpd:\
  71.         :lf=/usr/spool/lpd/errors:\
  72.         :rp=optrac.dom.ain:\
  73.         :rm=optrac.dom.ain:\
  74.         :sh:\
  75.         :sf:
  76.  
  77. #end of /etc/printcap file
  78.  
  79.    Steps:
  80.      * Fire up lpd (check /etc/rc.d/rc.M and /etc/rc.d/rc.inet2).
  81.      * If you are using straightforward lpr (meaning that the printer
  82.        itself *knows* how to talk lpd), then you can go directly using
  83.        lpr to print.
  84.      * If your printer cannot talk lpd and you are going via your Windows
  85.        95 or Windows NT printer share option, you need to use SAMBA.
  86.      * After making sure SAMBA works on your machine, use the smbprint
  87.        (in the SAMBA distribution) script to do the printing
  88.        (http://www.nijenrode.nl/~steven/ldp/Printing-HOWTO.html).
  89.        
  90.    Here's my copy of the smbprint script modified slightly:
  91.    
  92.    /usr/local/samba/bin/smbprint:
  93.  
  94. #!/bin/sh -x
  95.  
  96. # This script is an input filter for printcap printing on a unix machine. It
  97. # uses the smbclient program to print the file to the specified smb-based
  98. # server and service.
  99. # For example you could have a printcap entry like this
  100. #
  101. # smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
  102. #
  103. # which would create a unix printer called "smb" that will print via this
  104. # script. You will need to create the spool directory /usr/spool/smb with
  105. # appropriate permissions and ownerships for your system.
  106. #
  107. # Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton)
  108. # so that the server, service, and password can be read from
  109. # a /usr/var/spool/lpd/PRINTNAME/.config file.
  110. #
  111. # Script further modified to add user variable by h.pillay@ieee.org (Harish Pil
  112. lay)
  113. #
  114. # In order for this to work the /etc/printcap entry must include an
  115. # accounting file (af=...):
  116. #
  117. #   cdcolour:\
  118. #       :cm=CD IBM Colorjet on 6th:\
  119. #       :sd=/var/spool/lpd/cdcolour:\
  120. #       :af=/var/spool/lpd/cdcolour/acct:\
  121. #       :if=/usr/local/etc/smbprint:\
  122. #       :mx=0:\
  123. #       :lp=/dev/null:
  124. #
  125. # The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
  126. #   server=PC_SERVER
  127. #   service=PR_SHARENAME
  128. #   password="password"
  129. #   user=USERNAME          (added by h.pillay@ieee.org)
  130. #
  131. # E.g.
  132. #   server=PAULS_PC
  133. #   service=CJET_371
  134. #   password=""
  135. #   user=HARISH          (added by h.pillay@ieee.org)
  136.  
  137. #
  138. # Debugging log file, change to /dev/null if you like.
  139. #
  140. logfile=/tmp/smb-print.log
  141. # logfile=/dev/null
  142.  
  143.  
  144. #
  145. # The last parameter to the filter is the accounting file name.
  146. #   Extract the directory name from the file name.
  147. #   Concat this with /.config to get the config file.
  148. #
  149. eval acct_file=\$$#
  150. spool_dir=`dirname $acct_file`
  151. config_file=$spool_dir/.config
  152.  
  153. # Should read the following variables set in the config file:
  154. #   server
  155. #   service
  156. #   password
  157. #   user               (added by h.pillay@ieee.org)
  158. eval `cat $config_file`
  159.  
  160. #
  161. # Some debugging help, change the >> to > if you want to same space.
  162. #
  163. echo "server $server, service $service" >> $logfile
  164.  
  165. (
  166. # NOTE You may wish to add the line `echo translate' if you want automatic
  167. # CR/LF translation when printing.
  168.         echo translate
  169.         echo "print -"
  170.         cat
  171. ) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $user -
  172. N -P >> $logfile
  173.  
  174. #end of /usr/local/samba/bin/smbprint
  175.  
  176.    
  177.      _________________________________________________________________
  178.    
  179.    Hint from Rick Bressler :
  180.  
  181. Good tip sheet.  I use something very similar.  One helpful tip, this is not
  182. a particularly good idea:
  183.  
  184.         :lp=/dev/null:\
  185.  
  186. lpr does an 'exclusive' open on the file you specify as lp=.  It does this in
  187. order to prevent multiple processes from trying to print to the dame printer
  188. at the same time.
  189.  
  190. The side effect of this is that in your case, eng and colour can't print at
  191. the same time, (usually more or less transparent since they probably print
  192. quickly and since they queue you probably don't notice) but any other process
  193. that tries to write to /dev/null will break!
  194.  
  195. On a single user system, probably not a big problem.  I have a system with
  196. over 50 printers.  It would be a problem there.
  197.  
  198. The solution is to create a dummy printer for each.  Eg: touch /dev/eng.
  199.  
  200.    I have modified the lp entries in the printcap file above to take into
  201.    account Rick's suggestion. I did the following:
  202.    
  203.  
  204. #touch /dev/eng
  205. #touch /dev/colour
  206.  
  207.    Thanks Rick for the tip from the battlefield!
  208.    
  209.    
  210.      _________________________________________________________________
  211.    
  212.                                 SUCCESS STORY:
  213.                                        
  214.    What completely amazed me is how the printcap worked for both ways of
  215.    printing, lpr directly and lpr via smbprint. And, to top it all, how
  216.    the colour printing worked the first time round! Kudos to the ace
  217.    programmers!
  218.      _________________________________________________________________
  219.    
  220.    Questions? Email me.
  221.    
  222.    Go back to Harish's Home Page
  223.      _________________________________________________________________
  224.