home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / HOWTO / OTHER-FO / PRINTING.INF / PRINTING / Printing-HOWTO.info-2 < prev    next >
Encoding:
GNU Info File  |  1994-02-20  |  49.0 KB  |  1,134 lines

  1. This is Info file Printing-HOWTO.info, produced by Makeinfo-1.55 from
  2. the input file printing.texinfo.
  3.  
  4.    A guide to printing and previewing files under the Linux operating
  5. system.
  6.  
  7.    Copyright (C) 1994 by Grant Taylor and Brian McCauley
  8.  
  9. 
  10. File: Printing-HOWTO.info,  Node: More on the mx field,  Next: A test printcap entry,  Prev: More on the sh and sf fields,  Up: Setting up print services
  11.  
  12. More On The `mx' Field
  13. ----------------------
  14.  
  15.    This field allows you to limit the size of the print data to be
  16. spooled. The number you specify is in BUFSIZE blocks (1K under Linux).
  17. If you specify zero, the limit is removed, allowing print jobs to be
  18. limited only by available disk space. Note that the limit is on the
  19. size of the spooled data, *not* the amount of data sent to the physical
  20. printer. If a user tries to exceed this limit the file is tuncated. The
  21. user will see a message saying "lpr: <filename>: copy file is too
  22. large".
  23.  
  24.    For text physical printers, this is useful if you have users or
  25. programs that may deliberately or accidentally create excessively large
  26. output, but in most cases is not really very applicable.
  27.  
  28.    For PostScript physical printers, the limit is not useful at all,
  29. because a very small amount of spooled PostScript data can generate a
  30. large number of output pages.
  31.  
  32. 
  33. File: Printing-HOWTO.info,  Node: A test printcap entry,  Next: Putting It All Together,  Prev: More on the mx field,  Up: Setting up print services
  34.  
  35. A Test Printcap Entry
  36. ---------------------
  37.  
  38.    The following shell script is a very simple input filter - it simply
  39. concatenates its input onto the end of a file in `/tmp' after an
  40. appropriate banner. We specify this filter in our printcap entry and
  41. specify `/dev/null' as the print device. The print device will never
  42. actually be used, but we have to set it to something because otherwise
  43. the printer daemon will complain.
  44.  
  45.      #!/bin/sh
  46.      # This file should be placed in the printer's spool directory and
  47.      # named input_filter. It should be owned by root, group daemon, and be
  48.      # world executable (-rwxr-xr-x).
  49.      echo ------------------------------------------------ >> /tmp/testlp.out
  50.      date                                                  >> /tmp/testlp.out
  51.      echo ------------------------------------------------ >> /tmp/testlp.out
  52.      cat                                                   >> /tmp/testlp.out
  53.  
  54.    Here's the printcap entry. Notice the (reasonably) readable format
  55. and the use of continuation characters on all but the last line:
  56.  
  57.      myprinter|myprinter: \
  58.          :lp=/dev/null: \
  59.          :sd=/usr/spool/lpd/myprinter: \
  60.          :lf=/usr/spool/lpd/myprinter/errs: \
  61.          :if=/usr/spool/lpd/myprinter/input_filter: \
  62.          :mx#0: \
  63.          :sh: \
  64.          :sf:
  65.  
  66. 
  67. File: Printing-HOWTO.info,  Node: Putting It All Together,  Next: More On Remote Printing,  Prev: A test printcap entry,  Up: Setting up print services
  68.  
  69. Putting It All Together
  70. -----------------------
  71.  
  72.    Putting all the above bits together, here is a step by step guide to
  73. setting up a single printer on `/dev/lp0'. You can then extend this to
  74. other printers.  You have to be root do do all this, by the way.
  75.  
  76.   1. Check the permissions and locations of `lpr', `lprm', `lpc', `lpq'
  77.      and `lpd' *Note The important programs::.
  78.  
  79.   2. Create the spool directory for your printer, which we will call
  80.      `myprinter' for now. Make sure both are owned by root, group
  81.      daemon, and are user and group writeable, readonly for others
  82.      (-rwxrwxr-x).
  83.  
  84.           mkdir /usr/spool/lpd /usr/spool/lpd/myprinter
  85.           chown root.daemon /usr/spool/lpd /usr/spool/lpd/myprinter
  86.           chmod ug=rwx,o=rx /usr/spool/lpd /usr/spool/lpd/myprinter
  87.  
  88.   3. In the directory `/usr/spool/lpd/myprinter', create the necessary
  89.      files and give them the correct permissions and owner:
  90.  
  91.           cd /usr/spool/lpd/myprinter
  92.           touch .seq errs status lock
  93.           chown root.daemon .seq errs status lock
  94.           chmod ug=rw,o=r .seq errs status lock
  95.  
  96.   4. Create the shell script input_filter in the directory
  97.      `/usr/spool/lpd/myprinter'. Use the input filter given above. Make
  98.      sure that the file is owned by root, group daemon, and is
  99.      executable by anyone.
  100.  
  101.           cd /usr/spool/lpd/myprinter
  102.           chmod ug=rwx,o=rx input_filter
  103.  
  104.   5. Create the file `/etc/printcap' if it doesn't already exist. Remove
  105.      all entries in it and add the test printcap entry given above.
  106.      Make sure the file is owned by root, and readonly to everyone else
  107.      (-rw-r-r-).
  108.  
  109.   6. Edit the file `rc.local'. Add the line `/etc/lpd' to the end. This
  110.      will run the printer daemon each time the system boots. It is not
  111.      necessary to boot now though - just run it by hand:
  112.           lpd
  113.  
  114.   7. Do a test print:
  115.           ls -l | lpr -Pmyprinter
  116.  
  117.   8. Look in `/tmp' for a file called `testlp.out' - it should contain
  118.      your directory listing.
  119.  
  120.   9. Edit `/etc/printcap'. Copy the myprinter entry, so you have two
  121.      identical entries.
  122.  
  123.         * in the *first* entry, change both occurrences of `myprinter'
  124.           to `testlp' in the first line only
  125.  
  126.         * in the *second* entry, change `/dev/null' to your real print
  127.           device, eg., `/dev/lp0'
  128.  
  129.         * in the *second* entry, remove the `if' line completely
  130.  
  131.  10. Either reboot the system or kill the printer daemon and restart it.
  132.      This is because the printer daemon only looks at the /etc/printcap
  133.      file when it first starts up.
  134.  
  135.  11. Do a test print again - this one should come out on your physical
  136.      printer!
  137.           ls -l | lpr -Pmyprinter
  138.  
  139. 
  140. File: Printing-HOWTO.info,  Node: More On Remote Printing,  Next: The Fiddly Bits,  Prev: Putting It All Together,  Up: Setting up print services
  141.  
  142. More On Remote Printing
  143. -----------------------
  144.  
  145.    In order for any other machines to print using your printers, their
  146. names will have to be registered in either the file `/etc/hosts.equiv'
  147. or `/etc/hosts.lpd'.  These are simple text files, one host name per
  148. line.
  149.  
  150.    For preference, add hosts to `/etc/hosts.lpd'. `/etc/hosts.equiv' is
  151. used to give far wider access rights, and should be avoided wherever
  152. possible.
  153.  
  154.    You can restrict remote users either by group name (specify the
  155. groups permitted using one or more rg fields in `/etc/printcap' -
  156. `:rg=admin:' will restrict access to a printer to those users belonging
  157. to the group admin.  You can also restrict access to those users with
  158. accounts on your system, by specifying the boolean flag `:rs:' in your
  159. `/etc/printcap'.
  160.  
  161. 
  162. File: Printing-HOWTO.info,  Node: The Fiddly Bits,  Next: Troubleshooting,  Prev: More On Remote Printing,  Up: Setting up print services
  163.  
  164. The Fiddly Bits
  165. ---------------
  166.  
  167.    If all the above worked, you will now have two printers defined in
  168. `/etc/printcap' - one called testlp, which appends output to
  169. `/tmp/testlp.out', and one called myprinter which sends unmodified
  170. output to the physical printer attached to `/dev/lp0'. Both share the
  171. same spool directory. As an exercise, you might like to set up a
  172. separate spool directory for the testlp printer.
  173.  
  174.    If your printer is a PostScript printer, it may not be able to handle
  175. plain text. If this is the case, you'll need to set up a filter to
  176. convert plain text to PostScript. An excellent freeware program called
  177. nenscript is available which does just this. *Note PostScript::. If you
  178. don't set up such a filter, you will have to make sure by other means
  179. that the printer is sent only PostScript.
  180.  
  181.    You may like to add a line to your login script - or even to the
  182. default user login script - which sets up a `PRINTER' environment
  183. variable. Under bash, a suitable line would be `export
  184. PRINTER=myprinter'. This will prevent people having to specify
  185. `-Pmyprinter' every time they submit a print job.
  186.  
  187.    To add more printers, just repeat the above process with different
  188. printer names. Remember you can have multiple printcap entries all using
  189. the same physical device. This lets you treat the same device
  190. differently, depending on what you call it when you submit a print job
  191. to it.
  192.  
  193.    It is possible to "reuse" a printcap entry. If you specify your own
  194. machine as the remote host and another printer in your printcap file as
  195. the remote printer, you can effectively redirect print data from one
  196. printer to another.  Remember if you use this technique that all the
  197. data will be processed by all input filters in the chain and spooled for
  198. each printer it goes through.
  199.  
  200.    Although you can specify as many aliases for a printer as you like,
  201. it seems that for maximum usefulness the first two should be the same
  202. and should be the "real" printer name. Many programs will only ever use
  203. one of these two aliases.  The `lpc' command will only report on the
  204. first alias, though `lpc', `lpr', `lprm' and `lpq' all understand any
  205. alias.
  206.  
  207.    Rather than specify a maximum spool file size, you may want instead
  208. to prevent spool files expanding to fill your disk, even temporarily.
  209. To do so, put a file called minfree in each spool directory, specifying
  210. the amount of disk space that must remain for spooling data to be
  211. accepted. This file is a simple text file, containing the number of
  212. blocks to be left free. Usually this file is a link to a file in the
  213. main spool directory, as it is rare for different printers to have
  214. different minimums.
  215.  
  216. 
  217. File: Printing-HOWTO.info,  Node: Troubleshooting,  Prev: The Fiddly Bits,  Up: Setting up print services
  218.  
  219. Troubleshooting
  220. ---------------
  221.  
  222.    Problem: You get a message saying "lpd: connect: No such file or
  223. directory"
  224.  
  225.    Answer: The printer daemon `/etc/lpd' is not running. You may have
  226. forgotten to add it to your `/etc/rc.local' file. Alternatively you did
  227. add it, but haven't booted since. Add it and reboot, OR just run
  228. /etc/lpd. Remember you have to be root to do this. *Note lpd not
  229. working::.
  230.  
  231.    Problem: You get a message saying "Job queued, but cannot start
  232. daemon".
  233.  
  234.    Answer: This often appears right after the "lpd: connect" message.
  235. Same problem.
  236.  
  237.    Problem: You get a message saying "lpd: cannot create
  238. <spooldir>/.seq".
  239.  
  240.    Answer: You have not created the spool directory specified in the
  241. printcap entry or have misnamed it. An alternative (though much less
  242. likely) answer is that you have too little disk space left.
  243.  
  244.    Problem: You get a message saying "lpr: Printer queue is disabled".
  245.  
  246.    Answer: As root, use `lpc enable <PRINTERNAME>' to enable the
  247. printer. Note that as root, you can submit jobs even to a disabled
  248. printer.
  249.  
  250.    Problem: You submit a print job, there are no error messages, but
  251. nothing comes out on the physical printer.
  252.  
  253.    Answer: There could be many reasons. Make sure the physical printer
  254. is switched on, selected, and physically connected to the device
  255. specified in the `/etc/printcap' file. Use the `lpq' command to see
  256. whether the entry is in the queue. If it is, then the device may be
  257. busy, the printer may be down, or there may be an error on the printer.
  258. Check the error log specified in the printcap entry for clues. You can
  259. use the `lpc status' command to check whether the printer is down and
  260. `lpc up <PRINTERNAME>' to bring it back up if it is (you need to be
  261. root to do this).
  262.  
  263.    If after checking as suggested your print jobs still do not come out,
  264. double check that any input filter you have specified is present in the
  265. correct directory and has the correct permissions. If you are running
  266. syslogd, you can look in your logs for messages from lpd. If you see log
  267. entries saying "cannot execv <name of input filter>", then this is
  268. almost certainly the problem.
  269.  
  270.    Another possibility is that your printer is a PostScript printer and
  271. you are not sending PostScript to it. Most PostScript printers will
  272. ignore non-PostScript data. You may need to install an appropriate
  273. text-to-PostScript input filter.
  274.  
  275.    Lastly (and you'll feel really silly if this is the cause!) check
  276. that your input filter actually generates output and that the output
  277. device is not `/dev/null'.
  278.  
  279.    Problem: When remote printing, your jobs go into the remote queue
  280. but never get physically printed.
  281.  
  282.    Answer: If you can, look at the entry for the remote printer in the
  283. `/etc/printcap' file on the remote machine. It may be restricting your
  284. access.  The `rg' field restricts access to members of a specific group
  285. which you may not be in, and the `rs' field prevents access from users
  286. without accounts on the remote machine, which you may not have.
  287. Alternatively the printer on the remote machine may have been downed by
  288. the system administrator. *Note lpr over a network::.
  289.  
  290. 
  291. File: Printing-HOWTO.info,  Node: What lpr & lpd do,  Next: Getting hold of lpd,  Prev: Setting up print services,  Up: LPR
  292.  
  293. What lpr and lpd do
  294. ===================
  295.  
  296.    Most Un*x systems use `lpd' (or the System V variant `lp'), the line
  297. printer daemon, and friends to spool print jobs and run them through
  298. all needed filters.  While line printers are certainly on their way
  299. out, spooling print jobs and running them through filters is definitely
  300. a convenient thing.  Thus lpr.  (subliminal note: *PLEASE* find and
  301. read the `lpr', `lpd', `printcap', `lpc', `lpq', and `lprm' man pages.
  302. They are in the source dist of the net-2, if you haven't got them.)
  303.  
  304. 
  305. File: Printing-HOWTO.info,  Node: Getting hold of lpd,  Next: lpd files and permissions,  Prev: What lpr & lpd do,  Up: LPR
  306.  
  307. Getting hold of lpd
  308. ===================
  309.  
  310.    Lpd and family are available in several places.  The new Linux net-2
  311. package contains a working BSD-style lpd (although it has a couple of
  312. bugs and Makefile installs the binaries with the wrong permissions).  I
  313. now use this one with my stock 0.99pl14 kernel after following the
  314. directions in Matt Welsh's Net-2 HOWTO to get my NET-2 going (you only
  315. need loopback). Most people (and this document) consider this to be
  316. *the* Linux lpd package. A slightly debugged version incorporating
  317. patches from earlier releases of this HOWTO is also available in:
  318. `tsx-11.mit.edu:/pub/linux/packages/net/new-net-2/lpd-590p?.tar.gz'
  319.  
  320.    Some of the prepackaged Linux distributions have a very poor record
  321. with respect to having a working lpd packages so don't be shy of
  322. getting a new one if you seem to be having trouble.
  323.  
  324.    Fans of the SysV lp package should consider getting plp (however this
  325. HOWTO contains no information on that package)
  326.  
  327.    An lpd binary package which can be coaxed into working with the old
  328. net things (pre 0.99pl10 kernel) may still be around but you'll probably
  329. find it a bit shakey and you really should update your kernel.  Note a
  330. subtle difference between the two versions: the old one placed lock
  331. files and such in `/var/spool', while the net-2 version requires the
  332. directory `/var/spool/lpd' to exist for its lock file.
  333.  
  334.    You will need to edit `/etc/printcap' to configure lpd to use your
  335. printer. Setting up lpd to accept PostScript and print it is not very
  336. difficult; simply make a shell script filter. *Note Writing lpd
  337. filters::
  338.  
  339.    Setting up lpd correctly is definitely worth the trouble if you are
  340. going to do any printing at all.  Of course, if all you ever print is
  341. the occasional man page or instruction book, then you can probably get
  342. by without it (but even then it's nice).
  343.  
  344.    Ghostscript 2.6.x also comes with a complicated script and utilities
  345. to generate printcap entries and manage multiple types of queues for a
  346. printer.  I have not tested these, but I assume they can be made to
  347. work.  If you are in a large-scale environment with varied printing
  348. needs, these may be worth a look.
  349.  
  350. 
  351. File: Printing-HOWTO.info,  Node: lpd files and permissions,  Next: lpd not working,  Prev: Getting hold of lpd,  Up: LPR
  352.  
  353. Where Do The Files Go And What Should Their Permissions Be?
  354. ===========================================================
  355.  
  356.    There is quite a bit of variation between the various releases but
  357. I'll try where possible to offer solutions that are universally
  358. applicable. Start `lpd' in your `/etc/rc' or `/etc/rc.local' (usually
  359. in `/etc/rc.local' after you start `syslogd' (if you use `syslogd')).
  360.  
  361.    Set the group fields of the file permissons/ownership as follows:
  362.  
  363.      -rwxr-sr--   1 root     lp          37892 Nov 19 23:32 /etc/lpd
  364.      -rwxr-sr-x   1 root     lp          21508 Nov 19 23:32 /usr/bin/lpc
  365.      -rwsr-sr-x   1 root     lp          17412 Nov 19 23:32 /usr/bin/lpq
  366.      -rwxr-sr-x   1 root     lp          17412 Nov 19 23:32 /usr/bin/lpr
  367.      -rwxr-sr-x   1 root     lp          17412 Nov 19 23:32 /usr/bin/lprm
  368.      -rwxr-xr-x   1 root     lp           2816 May 10 13:37 /usr/bin/lptest
  369.      
  370.      ...and for each of the spool directories listed in the sd fields of
  371.      /etc/printcap...
  372.      
  373.      /var/spool/lpd:
  374.      total 5
  375.      drwxrwxr-x   2 root     lp           1024 May 18 23:00 .
  376.      drwxr-xr-x  11 root     root         1024 Feb 19 20:56 ..
  377.      -rw-rw-r--   1 root     lp              4 May 18 23:00 .seq
  378.      -rw-rw-r--   1 root     lp             18 May 18 23:00 lock
  379.      -rw-rw-r--   1 root     lp             25 May 18 23:00 status
  380.  
  381.    Note these 3 files are created by lpr and lpd so if you've never run
  382. these they will be absent. With some versions of the lpd package you
  383. had to touch them into being or they would be created with the wrong
  384. permissions but this bug seems to have been fixed.
  385.  
  386.    In older versions the group id was `daemon' not `lp'. There's also a
  387. named socket but `lpd' creates/deletes it as needed. Also you may find
  388. the uid is sometimes set to `daemon' or `lp' rather than `root' but
  389. this is of no consequence except on setuid binaries.
  390.  
  391.    These permissions are the most pedantic so don't be surprised if
  392. your system works with different permissions. On the other hand if lpd
  393. is not working for you and you have different permissions please try
  394. these before mailing us or posting to usenet. (This may sound obvious
  395. but you'd be amazed how much mail I've had from people with the
  396. permissions set wrong).
  397.  
  398.    People tell me that `lpr' must be setuid(root) but I've not seen
  399. evidence that this is really the case as long as the file permissions on
  400. the spool queues are right. Still as far as I know `lpr' is designed to
  401. be secure when installed setuid(root). This allows an alternative
  402. (sloppy) approach: just make `lpr' and `lprm' setuid(root) then you can
  403. almost forget the file permissions on the spool queues!
  404.  
  405.    You're free to choose different directories for the executables on
  406. your system (notably `lpc' is usually in `/etc' (or `/usr/sbin') even
  407. though it has commands that are useful to non-root). Of course since
  408. you are free to do this it implies the person who made up your
  409. distribution was also free to do so, so be carefull to make sure you
  410. delete old components when you install new ones.
  411.  
  412.    The master lpd lock file is fixed at compile time to be
  413. `/var/spool/lpd/lpd.lock' so you must have a `/var/spool/lpd directory'
  414. even if you choose not to keep your spool queue there. In the older
  415. binaries the lock file was `/usr/spool/lpd.lock' so this was not an
  416. issue.
  417.  
  418.    My advise is to keep your primary spool queue in `/usr/spool/lpd' and
  419. make `/var' a symlink to `usr' or keep it in `/var/spool/lpd' and make
  420. `/usr/spool' a symlink to `../var/spool'. This gives the greatest
  421. compatibility with the pathnames that are compiled into the various
  422. distributed binaries. Note that having a separate `/var' filesystem
  423. avoids the problem of your `/usr' filesystem filling up as a result of
  424. stuff in spool queues.
  425.  
  426.    The main configuration file is `/etc/printcap'. Network printing also
  427. uses `/etc/hosts.allow' and `/etc/hosts.lpd'.
  428.  
  429.    By now everyone should have libraries and binaries that look for
  430. config files in `/etc'. If you chose to keep your configs somewhere else
  431. (`/conf' or `/usr/etc' for example) then `/etc' must contain a symlink
  432. to the real file. If you still have a system which looks for files in
  433. `/usr/etc' or `/etc/inet' your system is way out of date and you should
  434. upgrade.
  435.  
  436. 
  437. File: Printing-HOWTO.info,  Node: lpd not working,  Next: Where Do I Get A Printcap For Printer Model xxxxx?,  Prev: lpd files and permissions,  Up: LPR
  438.  
  439. lpd not working
  440. ===============
  441.  
  442.    If `ps ax' does not reveal a `lpd' then you daemon has died (or was
  443. never started) - usually a sign that it couldn't create its lockfile,
  444. or was unable to find `/etc/services'.  (This will happen if you tried
  445. to start it before all your filesystems were mounted).
  446.  
  447.    If `lpr' works only for root then you've probably got a permission
  448. problem.
  449.  
  450.    If you cant even `cat' files to the printer then you may be using
  451. the wrong device name for the printer in `/etc/printcap' *Note Printer
  452. device names:: or you may need to fiddle with `tunelp'.  *Note hardware
  453. and drivers::.
  454.  
  455.    If you get "jobs queued, but cannot start daemon" or "lpc: connect:
  456. No such file or directory" while `lpd' is running then you are having
  457. trouble with the socket connection to `lpd'. "start" in the context of
  458. this error really means "wake". This problem has come and gone
  459. thoughout the history of Linux - I don't really understand this but it
  460. stems from an erroneous interaction between the networking stuff and
  461. "Unix domain" (non-network) sockets. Usually it has only shown up when
  462. the network is incorrectly configured. If you're not really on a
  463. network it is usually adequate just to have the following somewhere in
  464. your startup.
  465.  
  466.      ifconfig lo localhost
  467.      route add localhost
  468.  
  469.    You'll also need to have the `/etc/hosts' file. There's no need to
  470. run any daemons.
  471.  
  472.    There is second and much more understandable way to produce this
  473. error - use a mixture of components from different releases of lpd that
  474. use different names for the Unix domain socket (new stuff uses
  475. `/tmp/.printer', obsolete stuff `/dev/printer'). (For some time SLS was
  476. released this way).
  477.  
  478.    At the time of writing I am quite unable to reproduce this error - I
  479. am using my debugged version of the net-2 lpd compiled with gcc-2.4.5
  480. and libc-4.4.4 on kernel 0.99.14.
  481.  
  482. 
  483. File: Printing-HOWTO.info,  Node: Where Do I Get A Printcap For Printer Model xxxxx?,  Next: The Semantics of /etc/printcap,  Prev: lpd not working,  Up: LPR
  484.  
  485. Where Do I Get A Printcap For Printer Model xxxxx?
  486. ==================================================
  487.  
  488.    This question is essentially meaningless so please don't ask it on
  489. usenet *Note The Semantics of /etc/printcap::.
  490.  
  491. 
  492. File: Printing-HOWTO.info,  Node: The Semantics of /etc/printcap,  Next: The Syntax of /etc/printcap,  Prev: Where Do I Get A Printcap For Printer Model xxxxx?,  Up: LPR
  493.  
  494. The Semantics of `/etc/printcap'
  495. ================================
  496.  
  497.    Given the similarity in appearance and name between `/etc/termcap'
  498. and `/etc/printcap' one could be forgiven for assuming that they
  499. contain analogous infomation. This is not the case. Whereas
  500. `/etc/termcap' contains informations about terminal *types* - (mostly
  501. escape seqences) printcap contains information about *specific*
  502. printers (like the directory that holds the spool queue, the device
  503. name of the printer and what room it's in). The information about a
  504. printer model's escape sequences and so on are held in the various
  505. "filters" which are programs called by `lpd' to drive the printer.
  506. `/etc/printcap' simply gives the locations of these filters.  For
  507. details RTFM(printcap). [Alternatively the net-HOWTO has a summary of
  508. some of the more important fields.]
  509.  
  510.    One last point - you should always specify `suppress header' `:sh:'
  511. unless you have a *text* (not PostScript) printer and want banners. On
  512. a text printer they are usually a waste of time and paper. On a
  513. PostScript printer they usually stop your printer working.  *Note
  514. Burst/banner pages::.
  515.  
  516. 
  517. File: Printing-HOWTO.info,  Node: The Syntax of /etc/printcap,  Next: An /etc/printcap gotcha,  Prev: The Semantics of /etc/printcap,  Up: LPR
  518.  
  519. The Syntax of `/etc/printcap'
  520. =============================
  521.  
  522.    Ideally RTFM(termcap) (yes, I said *termcap*) but since most people
  523. don't have TFM(termcap) here are the essentials.
  524.  
  525.    Lines starting with `#' are comments (as you might have guessed).
  526.  
  527.    For each printer usable from the `lpr' command on your system there
  528. is one logical line in the file. For the sake of readability each
  529. logical line may be spread over several physical lines by making the
  530. last character on all but the last physical line a backslash.
  531.  
  532.    Each logical line has the following format:
  533.  
  534.      NAME1|NAME2|NAME3:STRING_CAPABILITY=STRING:\
  535.             :NUMERIC_CAPABILITY#NUMBER:BOOLEAN_CAPABILITY:
  536.  
  537.    The leading spaces and colon on the second line are for readability
  538. only.
  539.  
  540.    A printer can have as many names as you like but conventionally the
  541. final name is used as a longhand description of the printer. (Still
  542. people are free to say `lpr -P "grotty teletype in room 213"' if that's
  543. the description you've given.) One of the names of your default printer
  544. must be `lp'.
  545.  
  546.    The list of capabilities can be as long as needed and the order is
  547. not significant. Each "capability" is denoted by a two character code.
  548. (The name "capability" comes form the file format's termcap heritage -
  549. parameter or attribute would be a more sensible terms.) [Note from Ross
  550. Biro: capabilities with 3 character names don't work properly which is
  551. why the serial port stuff in the old binaries failed.]  Capabilities
  552. having string value and have a `=' delimiter between the capability
  553. name and the value while those having a numeric value use a `#'
  554. (actually they can use either a `#' or an `='). Boolean "capabilities"
  555. are true if they appear in the list and false if they do not.
  556.  
  557.    Special characters in a string value can be expressed using
  558. backslash-escaped sequences as in C; in addition, `\E' stands for ESC.
  559. `^' is also a kind of escape character; `^' followed by CHAR stands for
  560. the control-equivalent of CHAR.  Thus, `^a' stands for the character
  561. control-a, just like `\001'. `\' and `^' themselves can be represented
  562. as `\\' and `\^' respectively. `\:' for `:' seems to work but the
  563. source code contains a warning that it can confuse the parser and
  564. `\072' is a better idea.
  565.  
  566.    Example:
  567.      lp|bam|Epson FX-80:lp=/dev/lp1:sd=/usr/spool/lp1:sh:mx#0:\
  568.              :df=/usr/local/lib/magic-filter/lp.df:\
  569.              :if=/usr/local/lib/magic-filter/lp.if:
  570.  
  571.    The printer's name is `lp' (this is the printer that `lpr' uses by
  572. default). It's also known as `bam' or `"Epson FX-80"'.
  573.  
  574.    The printer is on `/dev/lp1' (aka AT-bus LPT1:). I don't want a burst
  575. page. I don't want a file length limit. Files queued by `lpr -d' are
  576. passed through `/usr/local/lib/magic-filter/lp.df' and those queued by
  577. `lpr' through `/usr/local/lib/magic-filter/lp.lf'.
  578.  
  579.    See also the next section.
  580.  
  581. 
  582. File: Printing-HOWTO.info,  Node: An /etc/printcap gotcha,  Next: The Minimum /etc/printcap,  Prev: The Syntax of /etc/printcap,  Up: LPR
  583.  
  584. An `/etc/printcap' gotcha
  585. =========================
  586.  
  587.    Two `/etc/printcap' files can look identical and yet one works and
  588. the other doesn't.
  589.  
  590.    See if `lpc stat' reports a printer called ` :'. The last character
  591. on a continued line must be a backslash. If there are whitespace
  592. characters after the backslash then it doesn't register the next line
  593. as a continuation.
  594.  
  595. 
  596. File: Printing-HOWTO.info,  Node: The Minimum /etc/printcap,  Next: The staircase effect,  Prev: An /etc/printcap gotcha,  Up: LPR
  597.  
  598. The Minimum /etc/printcap
  599. =========================
  600.  
  601.    This is a silly question but it is frequently asked. The answer is
  602. `lp:sh' (that's 6 bytes including the required linefeed character on
  603. the end). To use this `/etc/printcap' you must make `/dev/lp' a symlink
  604. to your printer and create your spool queue directory as
  605. `/usr/spool/lpd'.  (You might think that if you wanted banner pages you
  606. could loose the `:sh' but the termcap syntax requires at least one
  607. capability per entry).
  608.  
  609. 
  610. File: Printing-HOWTO.info,  Node: The staircase effect,  Next: Resetting The Printer After Each Printout,  Prev: The Minimum /etc/printcap,  Up: LPR
  611.  
  612. How to prevent the `Staircase Effect'
  613. =====================================
  614.  
  615.    Un*x terminates each line of a file with a linefeed but not a
  616. carriage return so taken literally a Un*x text file printed on an ASCII
  617. device will start each line below the end of the previous line.  Some
  618. printers can be set to treat "linefeed" as "carriage return, linefeed",
  619. others can't. If yours can then do simply do that. If the printer
  620. cannot be fixed create a shell script filter that reads:
  621.  
  622.      #!/bin/sh
  623.      if [ "$1" = -c ]; then
  624.        cat
  625.      else
  626.        sed -e s/$/^M/
  627.      fi
  628.      # the ``echo -ne'' assumes that /bin/sh is really bash
  629.      echo -ne \\f
  630.  
  631.    Where `^M' is a carriage return character not a `^' followed by a
  632. `M'.  To type `^M' in Emacs use the sequence `C-q C-m' and in vi use
  633. `C-v C-m'.  Conventionally this script is called `/usr/lib/lpf'. If you
  634. have more than one such script a better idea is to keep them in a
  635. subdirectory, say `/usr/lib/lpd/'. The test of `$1' allows the
  636. insertion of carriage returns to be switched off by `lpr -l'.
  637.  
  638.    Install this filter as the `if' filter by putting
  639. `:if=/usr/lib/lpf:' (or whatever) in your `/etc/printcap' entry for the
  640. printer.
  641.  
  642.    Alternatively your printer may have an escape sequence that will set
  643. the way it handles linefeed characters. A simple filter that uses an
  644. `echo -ne' command to send this sequence may be appropriate.
  645.  
  646.      #!/bin/sh
  647.      # Filter for HP printers to treat LF as CRLF
  648.      # the ``echo -ne'' assumes that /bin/sh is really bash
  649.      echo -ne \\033\&k2G
  650.      cat
  651.      echo -ne \\f
  652.  
  653. 
  654. File: Printing-HOWTO.info,  Node: Resetting The Printer After Each Printout,  Next: Preventing FF each file,  Prev: The staircase effect,  Up: LPR
  655.  
  656. Resetting the printer between each file printed
  657. ===============================================
  658.  
  659.    Either make your filters do it or define the `tr' "capability" in
  660. `/etc/printcap' to be your printer's font reset command. For details of
  661. the format of this string see the question on the format of printcap.
  662. This may not work if a printout crashes in the middle of an escape
  663. sequence - putting a lot of `^@' on the front may help but this
  664. probably won't be enough it you were printing raster graphics when the
  665. filter died.
  666.  
  667. 
  668. File: Printing-HOWTO.info,  Node: Preventing FF each file,  Next: lpd via serial port,  Prev: Resetting The Printer After Each Printout,  Up: LPR
  669.  
  670. Preventing formfeed after each file printed
  671. ===========================================
  672.  
  673.    If you don't have an `if' specified in `/etc/printcap' then `lpd'
  674. will automatically put a formfeed at the end of each file. If you're
  675. using a filter then it's up to the filter to decide if it wants to put
  676. a formfeed. To disable formfeed completely if you don't have an `if'
  677. put `:ff=:' in your `/etc/printcap'.  But please note this suppresses
  678. the formfeed that would usually be printed if a filter dies. If you
  679. want formfeeds after text printouts but not on printouts printed with
  680. `lpr -l' then create the following `if' filter:
  681.  
  682.      #!/bin/sh
  683.      # the ``echo -ne'' assumes that /bin/sh is really bash
  684.      cat
  685.      if [ "$1" != -c ]; then
  686.        echo -ne \\f
  687.      fi
  688.  
  689.    If you want a formfeed after `lpr -l' to be optional you can misuse
  690. the `-i' switch to suppress the formfeed with the following trick (after
  691. all `lpr -i -l' would usually not be implemented).
  692.  
  693.      #!/bin/sh
  694.      cat
  695.      # use lpr -i -l to print raw without trailing formfeed
  696.      if [ "$1" != -c -o "$4" = -i0 ]; then
  697.        # the ``echo -ne'' assumes that /bin/sh is really bash
  698.        echo -ne \\f
  699.      fi
  700.  
  701. 
  702. File: Printing-HOWTO.info,  Node: lpd via serial port,  Next: serial port cop out,  Prev: Preventing FF each file,  Up: LPR
  703.  
  704. Printing with lpd to a serial port
  705. ==================================
  706.  
  707.    The first if lpd complains about "ioctl(TIOCEXCL)" being
  708. unimplemented you need a version of lpd that doesn't care (eg.
  709. lpd-590p2)
  710.  
  711.    There are two sets of flags which you will need to set, plus the baud
  712. rate (Note: the `fc' flag setting seems to override the `br#'
  713. capability, so be sure to set that correctly as well as the `br#'!).
  714.  
  715.    Each of the flags can have bits set and cleared. Clearing is done
  716. first, so specify the clear flags (`fc#' and `xc#') before the set
  717. flags (`fs' and `xs').
  718.  
  719.    Setting the `br#' capability is self-explanatory. Example: `br#9600'
  720.  
  721.    It is very easy to translate from `stty' settings to printcap flag
  722. settings. If you need to, see the man page for stty now.
  723.  
  724.    Use stty to set up the printer port so that you can cat a file to it
  725. and have it print correctly. Here's what `stty -a' looks like for my
  726. printer port:
  727.  
  728.      dina:/usr/users/andy/work/lpd/lpd# stty -a < /dev/ttyS2
  729.      speed 9600 baud; rows 0; columns 0; line = 0;
  730.      intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
  731.      eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
  732.      lnext = ^V; min = 1; time = 0;
  733.      -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
  734.      -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr
  735.      -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel
  736.      -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
  737.      bs0 vt0 ff0
  738.      -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop
  739.      -echoprt -echoctl -echoke
  740.  
  741.    The only changes between this and the way the port is initialized at
  742. bootup are `-clocal', `-crtscts', and `ixon'. Your port may well be
  743. different depending on how your printer does flow control.
  744.  
  745.    Once you have your stty settings right, so that `cat file >
  746. /dev/ttyS2' (in my case) sends the file to the printer, look at the file
  747. `/usr/src/linux/include/linux/termios.h'. This contains a lot of
  748. `#define's and a few structs (You may wish to cat this file to the
  749. printer (you do have that working, right?) and use it as scratch paper
  750. - I (Andrew Tefft <teffta@engr.dnet.ge.com> did!). Go to the section
  751. that starts out
  752.  
  753.      /* c_cflag bit meaning */
  754.      #define CBAUD   0000017
  755.  
  756.    This section lists the meaning of the `fc#' and `fs#' bits.  You
  757. will notice that the names there (after the baud rates) match up with
  758. one of the lines of stty output. Didn't I say this was going to be easy?
  759.  
  760.    Note which of those settings are preceded with a - in your stty
  761. output. Sum up all those numbers (they are octal). This represents the
  762. bits you want to *clear*, so the result is your `fc#' capability.  Of
  763. course, remember that you will be setting bits directly after you
  764. clear, so you can just use `fc#0177777' (I do).
  765.  
  766.    Now do the same for those settings (listed in this section) which do
  767. not have a - before them in your stty output. In my example the
  768. important ones are CS8 (0000060), HUPCL (0002000), and CREAD (0000200).
  769. Also note the flags for your baud rate - mine is 0000015. Add those all
  770. up, and in my example you get 0002275. This goes in your `fs#'
  771. capability (`fs#02275' works fine in my example).
  772.  
  773.    Do the same with set and clear for the next section of the include
  774. file, "c_lflag bits". In my case I didn't have to set anything, so I
  775. just use `xc#0157777' and `xs#0'.
  776.  
  777.    Once your printcap is set up, try it out. If things don't work, see
  778. the next section.
  779.  
  780. 
  781. File: Printing-HOWTO.info,  Node: serial port cop out,  Next: Printers not in /dev,  Prev: lpd via serial port,  Up: LPR
  782.  
  783. cat works to the serial port, but not lpd (1)
  784. =============================================
  785.  
  786.    Generally getting lpd up and running is explained elsewhere, but if
  787. you are having trouble with serial port settings you can prevent `lpd'
  788. from trying to configure your port by treating you printer as one that
  789. does not present a normal device interface. *Note Printers not in
  790. /dev::.
  791.  
  792.   1. Set your printer (in your printcap) to `/dev/null1'. (`mknod
  793.      /dev/null1 c 1 3' because you don't want `/dev/null' to be opened
  794.      exclusively).
  795.  
  796.      remove the baud rate and flags settings from your printcap.
  797.  
  798.   2. Create a script such as this:
  799.  
  800.           #!/bin/sh
  801.           echo if: $* >> /var/spool/lpd/results
  802.           # /dev/lp is linked to /dev/ttyS2 which has the printer
  803.           exec your-old-input-filter $* > /dev/lp
  804.         ...or if you didn't have an old `if' installed...
  805.           #!/bin/sh
  806.           echo if: $* >> /var/spool/lpd/results
  807.           cat > /dev/lp
  808.           # the ``echo -ne'' assumes that /bin/sh is realy bash
  809.           echo -en \\f > /dev/lp
  810.  
  811.      Make sure it's world-executable and world-readable. Try out your
  812.      script (`/usr/lib/lpd/if < SOMEFILE') and see if it prints.
  813.  
  814.   3. Set the `if' capability in your printcap to call this script, e.g.
  815.      `if=/usr/lib/lpd/if'
  816.  
  817.   4. Use stty to correctly set your port settings. Try to print now.
  818.      You should be able to tell if things are being spooled, and things
  819.      *should* be printed, if your manual testing of the `if' script
  820.      works. But this is a kludge, so the idea is not to use the `if'
  821.      script.
  822.  
  823.    Assuming the above method using the `if' filter works and that you
  824. believe that you have specified what you think are the correct flags
  825. and baud rate in printcap; check `stty -a < /dev/ttyS2' (or whatever
  826. your printer port is).  If the settings are not correct, check your
  827. flags against your printout from termios.h. If the settings are *way*
  828. not correct, you may need a fixed lpd. The patch follows, and you can
  829. probably see why it's needed :-) Note: this patch is reversed and has
  830. already been applied (uh... unapplied :-) ) to lpd-590p2 so don't apply
  831. it if you already have that version or later.
  832.  
  833.    (the patch is coming in just a sec)
  834.  
  835.    When I was setting mine up, I followed a sequence like this:
  836.  
  837.      lprm WHATEVER # (make sure queue is empty and lpd is running)
  838.      stty CORRECT SETTINGS < /dev/ttyS2
  839.      lpr SOMETHING SMALL
  840.      stty -a < /dev/ttyS2  # (often had to ctrl-c out of this one)
  841.      
  842.      twiddle with flags
  843.      
  844.      lprm WHATEVER # make sure queue is empty again...
  845.  
  846.    Here's the patch (I it's reversed so apply it with `-R' - or, in
  847. practice, by hand!):
  848.  
  849.      -------------------------------Cut Here-------------------------------------
  850.      *** lpd-590/lpd/printjob.c  Thu Jul  8 20:56:59 1993
  851.      --- lpd-590/lpd/printjob.c~ Sat Feb 27 09:07:01 1993
  852.      ***************
  853.      *** 1271,1277 ****
  854.              }
  855.        #ifdef LINUX
  856.              ttybuf.c_cflag &= ~FC;          /* not quite right! */
  857.      !       ttybuf.c_cflag |= FS;           /* not quite right! */
  858.        #else
  859.              ttybuf.sg_flags &= ~FC;
  860.              ttybuf.sg_flags |= FS;
  861.      --- 1271,1277 ----
  862.              }
  863.        #ifdef LINUX
  864.              ttybuf.c_cflag &= ~FC;          /* not quite right! */
  865.      !       ttybuf.c_cflag |= ~FS;          /* not quite right! */
  866.        #else
  867.              ttybuf.sg_flags &= ~FC;
  868.              ttybuf.sg_flags |= FS;
  869.      -------------------------------Cut Here-------------------------------------
  870.  
  871. 
  872. File: Printing-HOWTO.info,  Node: Printers not in /dev,  Next: Burst/banner pages,  Prev: serial port cop out,  Up: LPR
  873.  
  874. Printers that are not simple devices
  875. ====================================
  876.  
  877.    [Firstly I'll explain the subject.] The most common example is a
  878. printer that is connected via a network in some strange way.  For
  879. example consider a printer connected to a host with which you can only
  880. communicate via E-mail.
  881.  
  882.    To use such a printer through `lpr' the `lp' capability of the print
  883. queue should be directed to a `/dev/null' type device (e.g. `mknod
  884. /dev/null1 c 1 3') but not `/dev/null' itself as `lpd' opens the device
  885. exclusively. Each filter must must explicitly uuencode and mail its
  886. output.
  887.  
  888.    In more complex cases if you already have an `if' or `of' filter for
  889. a strangely connected printer then other filters can pass their output
  890. to/through this filter to avoid duplication of effort.  In this case
  891. the `if' filter should usually be called with the `-c' switch to
  892. minimise the further manipulations if performs.
  893.  
  894.    I've heard someone has had some success trying something like this
  895. with Novell NetWare and the free mail transfer agent "Charon".
  896.  
  897. 
  898. File: Printing-HOWTO.info,  Node: Burst/banner pages,  Next: Spooling text to a PS printer,  Prev: Printers not in /dev,  Up: LPR
  899.  
  900. Generating burst or banner pages
  901. ================================
  902.  
  903.    For a simple text printer (in particular not PostScript) and a
  904. simple text banner simply take `:sh:' out of the printcap record. If you
  905. want to prevent the banner comming out in whatever font was last used
  906. on the printer then define the `tr' "capability" to be your printer's
  907. font reset command.
  908.  
  909.    If you want a fancy customised banner (or have a PostScript printer)
  910. leave `:sh:' in the printcap and make each of your filters print the
  911. banner. All the information to put on the banner is included in the
  912. filter's positional parameters.  RTFM(printcap) for details. [ If
  913. you're using <B.A.McCauley@bham.ac.uk>'s magic-filter package then call
  914. the code to print the banners from the config script. ]
  915.  
  916. 
  917. File: Printing-HOWTO.info,  Node: Spooling text to a PS printer,  Next: Trunation of graphics files,  Prev: Burst/banner pages,  Up: LPR
  918.  
  919. Spooling text to a PostScript printer
  920. =====================================
  921.  
  922.    You need a filter based on a program that converts ascii to
  923. PostScript. The most well known of these is `enscript' but it's also
  924. the hardest to find (being non-free). Others include `a2ps',
  925. `nenscript', and `mpage'. *Note Printing text via PostScript::.
  926.  
  927. 
  928. File: Printing-HOWTO.info,  Node: Trunation of graphics files,  Next: Why lpr -i does not work,  Prev: Spooling text to a PS printer,  Up: LPR
  929.  
  930. Why graphics files are sometines truncated
  931. ==========================================
  932.  
  933.    This is usually because you've got a limit set on the maximum size
  934. file that can sit in the spool queue. Put `mx#0' in your printcap.
  935.  
  936. 
  937. File: Printing-HOWTO.info,  Node: Why lpr -i does not work,  Next: Why lpr -p does not work,  Prev: Trunation of graphics files,  Up: LPR
  938.  
  939. Why `lpr -i' doesn't work
  940. =========================
  941.  
  942.    To get `lpr -i' to work you need a filter installed as `if' that
  943. implements it.  The `-i' switch is simply passed on by `lpd' to the
  944. filter.  The filter called `lpf' that comes with `lpd' supports this
  945. feature but can only be used to print text.  If you whant to use this
  946. program but still want your filter to do some printer specific
  947. initialisation then write script thus:
  948.  
  949.      #!/bin/sh
  950.      # My initialisation stuff goes here
  951.      exec /usr/lib/lpf $*
  952.  
  953.    More reasonably you could have your filter script send the printer
  954. left margin sequence.
  955.  
  956.      #!/usr/bin/perl
  957.      # This example is in perl for a change because converting numbers
  958.      # to characters is tricky in shell script
  959.      
  960.      for ($i=0; !($_ = $ARGV[$i]) || !/^-i([0-9])+/; $i++) {}
  961.      
  962.      print pack("cAc",27,"l",$1);
  963.      
  964.      while (<STDIN>) { print; }
  965.  
  966. 
  967. File: Printing-HOWTO.info,  Node: Why lpr -p does not work,  Next: "no daemon present",  Prev: Why lpr -i does not work,  Up: LPR
  968.  
  969. Why `lpr -p' doesn't work?
  970. ==========================
  971.  
  972.    Because it's broken. `lpd' always thinks that the printer is 0
  973. characters wide regardless of what `/etc/printcap' or the `lpr'
  974. arguemnts say. The lpd-FAQ contained a patch but it has now been
  975. applied to lpd-590p1 and later. (Appologies to anyone who wanted this
  976. patch after the lpd-FAQ merged with printing-how.to. It was dropped in
  977. the mistaken belief that a new release of lpd-590 was iminent).
  978.  
  979.    One other thing: `lpd' calls `pr' by full pathname so if you keep
  980. `pr' somewhere different from `/usr/bin/pr' you will need a symlink.
  981. (Where `lpd' expects to find `pr' may vary from version to version).
  982.  
  983. 
  984. File: Printing-HOWTO.info,  Node: "no daemon present",  Next: lpr over a network,  Prev: Why lpr -p does not work,  Up: LPR
  985.  
  986. `lpc' and `lpq' warning of missing daemons
  987. ==========================================
  988.  
  989.    One `lpd' process runs all the time and it spawns children to handle
  990. each printer as needed. The health of the master daemon is not
  991. explicity reported by `lpc' but the absence of errors indicates that it
  992. is healthy. *Note lpd not working::. The `lpc stat' command will
  993. display the message "no daemon present" for each queue that is not
  994. actually printing at the time - this is completely normal. If printing
  995. has been disabled or the queue is empty then this is not an error
  996. condition. `lpq' is even more alarmist and will say "Warning: no daemon
  997. present". If the daemon is absent when the queue has entries and has
  998. not been explicitly stopped then this warning probably indicates an
  999. error in a filter. Fix the filter then use `lpd up QUEUE-NAME' to
  1000. restart it.
  1001.  
  1002.    Sometimes when shutting down a printer `lpc' will get confused and
  1003. try to kill a non existant daemon. This leads to irritating but harmless
  1004. error messages. In lpd-590p2 these are much rarer.
  1005.  
  1006. 
  1007. File: Printing-HOWTO.info,  Node: lpr over a network,  Next: Writing lpd filters,  Prev: "no daemon present",  Up: LPR
  1008.  
  1009. Using `lpr' over a network
  1010. ==========================
  1011.  
  1012.    To print on the printer listed as `foo' in the printcap on machine
  1013. `bar.baz.net' from the machine `mine.baz.net' you put an entry like
  1014. this in your `/etc/printcap' (on `mine.baz.net'):
  1015.  
  1016.      foo:lp=:rm=bar.baz.net:rp=foo:sd=/usr/lpd/spool/foo:
  1017.  
  1018.    and, of course, create the spool directory `/usr/lpd/spool/foo'.
  1019.  
  1020.    There's no point specifying filters and the like in
  1021. `mine.baz.net:/etc/printcap' as it's the ones in
  1022. `bar.baz.net:/etc/printcap' that will get used.
  1023.  
  1024.    On the machine `bar.baz.foo', you need to put `mine.baz.net' on a
  1025. line by itself in either `/etc/hosts.equiv' or `/etc/hosts.lpd'; note
  1026. that putting it in `/etc/hosts.equiv' will allow for unauthenticated
  1027. logins as well as printing.  `/etc/hosts.lpd' is for printing only.
  1028.  
  1029.    The machines listed in `/etc/hosts.*' should be described canonical
  1030. names or numbers as lpd starts with the IP address and performs a
  1031. revervse DNS lookup to get the name. If you are not sure of cannonical
  1032. name you can just list all the names you know for a machine. (If you
  1033. have `dig' then the command `dig -x A.B.C.D' can be used to get the
  1034. canonical name of IP address A.B.C.D.)
  1035.  
  1036.    If the printer server is not nunning a BSD style spooler then it
  1037. should still be possible to get it to work but the authority files may
  1038. have a different names or formats. For example Chris Nystrom
  1039. <chrisn@medianet.com> found that he had to create a file on the remote
  1040. machine called `/usr/spool/lp/admins/lp/Systems' that listed his Linux
  1041. box's name. We do not know if this is a SYSV thing or something
  1042. exclusive to dynix/ptx 2.0.3 that he is using on his Sequent.
  1043.  
  1044.    If you can't get remote printing to work thrugh lpd you may be able
  1045. to simply use remote command exectution like this:
  1046.  
  1047.      rsh bar.baz.net "lp -dlp" < FILE
  1048.  
  1049.    This example would be for a remote system using a SYSV type printing
  1050. system on host `bar.baz.net'.
  1051.  
  1052. 
  1053. File: Printing-HOWTO.info,  Node: Writing lpd filters,  Next: Debuging filters,  Prev: lpr over a network,  Up: LPR
  1054.  
  1055. Writing lpd filters
  1056. ===================
  1057.  
  1058.    In normal Un*x terminology, filters are just programs (so they must
  1059. have execute permission) that read a stream from their standard input
  1060. and write to their standard output.
  1061.  
  1062.    lpd filters are filters in the sense that thay read STDIN and write
  1063. to STDOUT, but are unusual in that they may assume that their standard
  1064. input is a random acess file file and may perform lseek() operations on
  1065. it.
  1066.  
  1067.    All lpd filters have a common command line syntax (or more often
  1068. simply ignore command line parameters). For details of the command line
  1069. parameters RTFM(printcap).
  1070.  
  1071.    If you want to write a shell script filter it must have a #!/bin/sh
  1072. (or perl or csh) header.  Here is the generic form of a filter to
  1073. accept PostScript.
  1074.  
  1075.      #!/bin/sh
  1076.      /PATH.../gs -q -dSAFER -dNOPAUSE -r??? -sDevice=?????? -sOutputFile=- -
  1077.  
  1078.    Place the full pathname of the script as one of the filters (but not
  1079. `of'!) parameter in the printcap for your printer.  I suggest putting
  1080. such scripts in `/usr/lib/lpd/'. It is also usual to keep filters in
  1081. the spool directories but this goes against normal practice of keeping
  1082. programs and data neatly apart.  (`-dSAFER' attempts to protect against
  1083. PostScript interpreter security holes, `-q' and `-dNOPAUSE' make it run
  1084. nonstop, and Device is the appropriate special file for your printer).
  1085.  
  1086.    Here is an Epson FX-80 dvi filter using ghostscript:
  1087.  
  1088.      #!/bin/sh
  1089.      /usr/TeX/bin/dvips -f | \
  1090.                    /usr/bin/gs -q -dSAFER -sDEVICE=eps9high -r120x216 \
  1091.                    -dNOPAUSE -sOutputFile=- -
  1092.  
  1093.    More tools useful for making filters are described elsewhere in this
  1094. document.
  1095.  
  1096. 
  1097. File: Printing-HOWTO.info,  Node: Debuging filters,  Next: Output filters,  Prev: Writing lpd filters,  Up: LPR
  1098.  
  1099. Debuging lpd filters
  1100. ====================
  1101.  
  1102.    It's easier to debug filters if you test them in an immediate shell
  1103. before you install them. (If your filter makes use of its command line
  1104. arguments you'll have to specify them too).  `my-new-filter <FILE
  1105. >/dev/lp1'
  1106.  
  1107.    A trick most people find useful when testing filters that make use of
  1108. their command line arguments is to include `echo $* >>/tmp/filter-log'
  1109. near the top of the script.
  1110.  
  1111.    If the filter works when you test it but still doesn't work when
  1112. called by `lpd' then you may have forgotten the `#!/bin/sh' header. You
  1113. may also need to set PATH within the script since the daemon's PATH may
  1114. not have everything you need. Note also that the filter is run with
  1115. uid=daemon so any programs it calls sould be world executable.
  1116.  
  1117. 
  1118. File: Printing-HOWTO.info,  Node: Output filters,  Next: Filters for given printers,  Prev: Debuging filters,  Up: LPR
  1119.  
  1120. Output (`of') filters
  1121. =====================
  1122.  
  1123.    Never use these. (Well strictly speaking there are circumstances but
  1124. you're unlikey to meet them). Recently (early '94) there has been a
  1125. spate of preople on c.o.l.help advokating the use of output filters.
  1126. Using `of' filters means that if a printout is queued while another is
  1127. already printing the 2 will be run together with a form-feed between.
  1128. Any printer initialisation or file type detection will therfore not be
  1129. performed for the second file and it will probably be printed
  1130. incorrectly. There are other more subtle ways in which output filters
  1131. can do unexpected things. IMHO: If using an output filter is the
  1132. answer, it was probably a silly question.
  1133.  
  1134.