home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LINUX / HOWTO / mini / prn2win.txt < prev    next >
Text File  |  1997-07-07  |  7KB  |  219 lines

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