📄 410-412.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Printing</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=20//-->
<!--PAGES=410-412//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="408-410.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="412-416.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading12"></A><FONT COLOR="#000077">Understanding the Important Files</FONT></H3>
<P>Apart from the programs discussed so far, each spool directory contains files that have the permissions -rw-rw-r-:
</P>
<DL>
<DD><B>•</B> The /etc/printcap file contains the printer specifications for each named printer in your system.
<DD><B>•</B> The .seq file contains the job number counter for <TT>lpr</TT> to assign.
<DD><B>•</B> The status file contains the message to be reported by <TT>lpc stat</TT>.
<DD><B>•</B> The lock file is used by <TT>lpd</TT> to prevent itself from trying to print two jobs to the same printer at once.
<DD><B>•</B> The errs file logs printer failures.
</DL>
<P>The errs file isn’t required by Linux in order to print, but the file must exist for <TT>lpd</TT> 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.</P>
<P>One very important file is /etc/printcap, which the following section describes in detail.</P>
<H3><A NAME="Heading13"></A><FONT COLOR="#000077">Understanding the /etc/printcap File</FONT></H3>
<P>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- -.
</P>
<P>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 <TT>printcap</TT>, 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 <TT>lpd</TT> sources if you don’t already have it.</P>
<P>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:</P>
<!-- CODE SNIP //-->
<PRE>
# 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:
</PRE>
<!-- END CODE SNIP //-->
<P>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.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>If you don’t designate a default printer via an environment variable or don’t specify a printer on the <TT>lpr</TT> command line, Linux will route the print job to the <TT>lp</TT> printer. Thus, you should specify one of the printers in the printcap file as the <TT>lp</TT> printer.<HR></FONT>
</BLOCKQUOTE>
<P>Programs that change the data before it’s sent to the physical printer are called <I>filters</I>. It’s possible for a filter to send no data at all to a physical printer—that is, the filter filters out everything.</P>
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">Understanding the Fields in /etc/printcap</FONT></H4>
<P>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.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 20.3</B> The /etc/printcap Fields
<TR>
<TH COLSPAN="3"><HR>
<TR>
<TH WIDTH="10%" ALIGN="LEFT">Field
<TH WIDTH="15%" ALIGN="LEFT">Type
<TH WIDTH="65%" ALIGN="LEFT">Description
<TR>
<TD COLSPAN="3"><HR>
<TR>
<TD><TT>lp</TT>
<TD>String
<TD>Specifies the device to print to—for example, <TT>/dev/lp0</TT>
<TR>
<TD><TT>sd</TT>
<TD>String
<TD>Specifies the name of the spool directory for this printer
<TR>
<TD VALIGN="TOP"><TT>lf</TT>
<TD VALIGN="TOP">String
<TD>Specifies the file that errors on this printer are to be logged to
<TR>
<TD><TT>if</TT>
<TD>String
<TD>Specifies the input filter name
<TR>
<TD><TT>rm</TT>
<TD>String
<TD>Specifies the name of a remote printing host
<TR>
<TD><TT>rp</TT>
<TD>String
<TD>Specifies the name of a remote printer
<TR>
<TD><TT>sh</TT>
<TD>Boolean
<TD>Specifies this to suppress headers (banner pages)
<TR>
<TD><TT>sf</TT>
<TD>Boolean
<TD>Specifies this to suppress end-of-job form feeds
<TR>
<TD VALIGN="TOP"><TT>mx</TT>
<TD VALIGN="TOP">Numeric
<TD>Specifies the maximum allowable print job size (in blocks)
<TR>
<TD COLSPAN="3"><HR>
</TABLE>
<P><FONT SIZE="+1"><B>The <I>lp</I> Field
</B></FONT></P>
<P>If you specify /dev/null as the print device, all other processing is performed correctly, but the final data goes to the <I>bit bucket</I>—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 <TT>rm</TT> and <TT>rp</TT> fields), specify <TT>:lp=:</TT>.</P>
<P>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.</P>
<P><FONT SIZE="+1"><B>The <I>lf</I> Field
</B></FONT></P>
<P>Whatever file you specify should already exist, or logging doesn’t occur.
</P>
<P><FONT SIZE="+1"><B>The <I>if</I> Field
</B></FONT></P>
<P><I>Input filters</I> 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.</P>
<P>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.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="408-410.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="412-416.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -