-->
Previous Table of Contents Next


Understanding the Important Files

Apart from the programs discussed so far, each spool directory contains files that have the permissions -rw-rw-r-:

  The /etc/printcap file contains the printer specifications for each named printer in your system.
  The .seq file contains the job number counter for lpr to assign.
  The status file contains the message to be reported by lpc stat.
  The lock file is used by lpd to prevent itself from trying to print two jobs to the same printer at once.
  The errs file logs printer failures.

The errs file isn’t required by Linux in order to print, but the file must exist for lpd to be able to log printer failures. The errs file can be called whatever you like as long as the name is specified in /etc/printcap. The errs file is usually created manually when you set up the spool area. The section “Putting It All Together,” later in this chapter, has more on this.

One very important file is /etc/printcap, which the following section describes in detail.

Understanding the /etc/printcap File

The /etc/printcap file is a text file that you can edit with your favorite editor. /etc/printcap should be owned by root and have the permissions -rw-r- - r- -.

The contents of /etc/printcap typically look very cryptic, but when you know how the file works, the contents are much easier to understand. To compound the problem, in some distributions there’s no man page for printcap, and most printcap files are created either by programs or by people with no thought for readability. For your own sanity, make the layout of your printcap file as logical and readable as possible with lots of comments. And get the man page from the lpd sources if you don’t already have it.

One printcap entry describes one printer. Essentially, a printcap entry provides a logical name for a physical device and then describes how data sent to that device should be handled. For example, a printcap entry defines what physical device is to be used, what spool directory any data for that device should be stored in, what preprocessing should be performed on the data, where errors on the physical device should be logged, and so forth. You can limit the amount of data that may be sent in a single job, or limit access to a printer to certain classes of users. The following shows how a printer is defined in the printcap file:


# Sample printcap entry with two aliases

myprinter|laserwriter:\

# lp is the device to print to - here the first parallel printer.

:lp=/dev/lp0: \

# sd means spool directory - where print data is collected

:sd=/usr/spool/lpd/myprinter:

It’s okay to have multiple printcap entries defining several different ways to handle data destined for the same physical printer. For example, a physical printer may support PostScript and HP LaserJet data formats, depending on some setup sequence being sent to the physical printer before each job. It makes sense to define two printers: one that preprocesses the data by preappending the HP LaserJet sequence and one that preappends the PostScript sequence. Programs that generate HP data send it to the HP printer, whereas programs generating PostScript print to the PostScript printer.


NOTE:  If you don’t designate a default printer via an environment variable or don’t specify a printer on the lpr command line, Linux will route the print job to the lp printer. Thus, you should specify one of the printers in the printcap file as the lp printer.

Programs that change the data before it’s sent to the physical printer are called filters. It’s possible for a filter to send no data at all to a physical printer—that is, the filter filters out everything.

Understanding the Fields in /etc/printcap

The printcap file has too many fields to describe fully in this chapter, so only the most important ones are described. All fields in /etc/printcap (except for the names of the printer) are enclosed between colons and denoted by a two-letter code. The two-letter code is followed by a value that depends on the type of field. There are three types of fields: string, Boolean, and numeric. Table 20.3 describes the most common and most important fields; the following sections go into more detail.

Table 20.3 The /etc/printcap Fields

Field Type Description

lp String Specifies the device to print to—for example, /dev/lp0
sd String Specifies the name of the spool directory for this printer
lf String Specifies the file that errors on this printer are to be logged to
if String Specifies the input filter name
rm String Specifies the name of a remote printing host
rp String Specifies the name of a remote printer
sh Boolean Specifies this to suppress headers (banner pages)
sf Boolean Specifies this to suppress end-of-job form feeds
mx Numeric Specifies the maximum allowable print job size (in blocks)

The lp Field

If you specify /dev/null as the print device, all other processing is performed correctly, but the final data goes to the bit bucket—that is, to nowhere. Printing to nowhere is rarely useful except for test printer configurations or with weird printers. When you’re setting up a remote printer (that is, you’ve specified rm and rp fields), specify :lp=:.

Don’t leave the field empty unless you’re using a remote printer. The printer daemon complains if you don’t specify a print device.

The lf Field

Whatever file you specify should already exist, or logging doesn’t occur.

The if Field

Input filters are programs that take print data on their standard input and generate output on their standard output. A typical use of an input filter is to detect plain ASCII text and convert it into PostScript—that is, raw text is its input and PostScript is its output.

When you specify an input filter, the printer daemon doesn’t send the spooled print data to the specified device. Instead, it runs the input filter with the spooled data as standard input and the print device as standard output.


Previous Table of Contents Next