⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 412-416.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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=412-416//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="410-412.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="416-420.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P><FONT SIZE="+1"><B>The <I>rm</I> and <I>rp</I> Fields

</B></FONT></P>

<P>Sending your print data to a printer attached to another machine is as simple as specifying the remote machine <TT>rm</TT> and the remote printer <TT>rp</TT> and making sure that the print device field <TT>lp</TT> is empty.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>Data is still spooled locally before it&#146;s transferred to the remote machine. Any input filters you specify are also run.<HR></FONT>

</BLOCKQUOTE>

<P><FONT SIZE="+1"><B>The <I>sh</I> and <I>sf</I> Fields

</B></FONT></P>

<P>Unless you have a lot of different people using your printer, you&#146;re most likely not interested in banner pages, so specify <TT>sh</TT>.</P>

<P>Suppressing form feeds, by specifying <TT>sf</TT>, is most useful if your printer is typically used for output from word-processing packages. Most word-processing packages create complete pages of data, so if the printer daemon is adding a form feed to the end of each job, you get a blank page after each job. If the printer is usually used for program or directory listings, however, having that form feed ensures that the final page is completely ejected, so each listing starts at the top of a new page.</P>

<P><FONT SIZE="+1"><B>The <I>mx</I> Field

</B></FONT></P>

<P>The <TT>mx</TT> field allows you to limit the size of the print data to be spooled. The number you specify is in <TT>BUFSIZE</TT> blocks (1KB under Linux). If you specify zero, the limit is removed, allowing print jobs to be limited only by available disk space.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The limit is on the size of the spooled data, not the amount of data sent to the physical printer.<HR></FONT>

</BLOCKQUOTE>

<P>If a user tries to exceed this limit, the file is truncated. The user sees a message saying this:

</P>

<!-- CODE SNIP //-->

<PRE>

(lpr: file-name: copy file is too large)

</PRE>

<!-- END CODE SNIP //-->

<P>For non-PostScript printers, this limit is useful if you have users or programs that may deliberately or accidentally create excessively large output. For PostScript printers, the limit isn&#146;t useful at all because a very small amount of spooled PostScript data can generate a large number of output pages.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Setting the <I>PRINTER</I> Environment Variable

</FONT></H4>

<P>You may want to add a line to your login script&#151;or even to the default user login script&#151;that sets up a <TT>PRINTER</TT> environment variable. Under the <TT>bash</TT> shell, a suitable line is <TT>export</TT> <TT>PRINTER=myprinter</TT>. This prevents people from having to specify <TT>-Pmyprinter</TT> every time they submit a print job.</P>

<P>To add more printers, just repeat this process with different printer names. Remember that you can have multiple printcap entries, all using the same physical device. This way, you can treat the same device differently, depending on what you call it when you submit a print job to it.</P>

<H3><A NAME="Heading16"></A><FONT COLOR="#000077">Creating a Test printcap Entry</FONT></H3>

<P>The following shell script is a very simple input filter&#151;it simply concatenates its input onto the end of a file in /tmp after an appropriate banner. Specify this filter in the printcap entry and specify /dev/null as the print device. The print device is never actually used, but you have to set it to something; otherwise, the printer daemon complains.

</P>

<!-- CODE SNIP //-->

<PRE>

#!/bin/sh

# This file should be placed in the printer&#146;s spool directory and

# named input_filter. It should be owned by root, group daemon, and

# be world executable (-rwxr-xr-x).

echo ------------------------------------------------ &gt;&gt; /tmp/

date                                                  &gt;&gt; /tmp/

echo ------------------------------------------------ &gt;&gt; /tmp/

cat                                                   &gt;&gt; /tmp/

</PRE>

<!-- END CODE SNIP //-->

<P>In the following printcap entry, notice the reasonably readable format and the use of the continuation character (<TT>\</TT>) on all but the last line:</P>

<!-- CODE SNIP //-->

<PRE>

myprinter|myprinter: \

:lp=/dev/null: \

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

:lf=/usr/spool/lpd/myprinter/errs: \

:if=/usr/spool/lpd/myprinter/input_filter: \

:mx#0: \

:sh: \

:sf:

</PRE>

<!-- END CODE SNIP //-->

<H3><A NAME="Heading17"></A><FONT COLOR="#000077">Putting It All Together</FONT></H3>

<P>To put all the preceding bits together, the following steps guide you through setting up a single printer on /dev/lp0. You can then extend this to other printers. (You have to be root to do all this, by the way.)

</P>

<DL>

<DD><B>1.</B>&nbsp;&nbsp;Check the permissions and locations of <TT>lpr</TT>, <TT>lprm</TT>, <TT>lpc</TT>, <TT>lpq</TT>, and <TT>lpd</TT>. Earlier in this chapter, Table 20.2 listed the correct settings and directories.

<DD><B>2.</B>&nbsp;&nbsp;Create the spool directory for your printer (named myprinter for now). Make sure that both the directory and printer are owned by root, belong to the daemon group, and have write permissions for user and group and read-only permission for others (-rwxrwxr-x). Use the following commands:

<!-- CODE SNIP //-->

<PRE>

   mkdir /usr/spool/lpd

   mkdir /usr/spool/lpd/myprinter

   chown root.daemon /usr/spool/lpd /usr/spool/lpd/myprinter

   chmod ug=rwx,o=rx /usr/spool/lpd /usr/spool/lpd/myprinter

</PRE>

<!-- END CODE SNIP //-->

<DD><B>3.</B>&nbsp;&nbsp;In the /usr/spool/lpd/myprinter directory, create the necessary files and give them the correct permissions and owner. Use the following commands:

<!-- CODE SNIP //-->

<PRE>

   cd /usr/spool/lpd/myprinter

   touch .seq errs status lock

   chown root.daemon .seq errs status lock

   chmod ug=rw,o=r .seq errs status lock

</PRE>

<!-- END CODE SNIP //-->

<DD><B>4.</B>&nbsp;&nbsp;Create the shell script <TT>input_filter</TT> in the /usr/spool/lpd/myprinter directory. Use the input filter given earlier in the section &#147;Creating a Test printcap Entry&#148; for your filter. Make sure that the file is owned by root, belongs to the daemon group, and is executable by anyone. Use the following commands:

<!-- CODE SNIP //-->

<PRE>

   cd /usr/spool/lpd/myprinter

   chmod ug=rwx,o=rx input_filter

</PRE>

<!-- END CODE SNIP //-->

<DD><B>5.</B>&nbsp;&nbsp;Create the /etc/printcap file if it doesn&#146;t already exist. Remove all entries in it and add the test printcap entry given in the &#147;Creating a Test printcap Entry&#148; section. Make sure that the file is owned by root and is read-only to everyone else. You can use the <TT>chmod</TT> command to set the proper file permissions: -rw-r- - r- - (or 644 in octal).

<DD><B>6.</B>&nbsp;&nbsp;Edit the rc.local file (you can use any ASCII editor, such as <TT>vi</TT> or <TT>emacs</TT>). Add the line /etc/lpd to the end to run the printer daemon each time the system boots. It&#146;s not necessary to boot now, however; just run it by hand with the <TT>lpd</TT> command.

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR>&#149; <B>See</B> &#147;Starting <TT>vi</TT> by Using an Existing File,&#148; <B>p. 183</B><HR></FONT>

</BLOCKQUOTE>

<DD><B>7.</B>&nbsp;&nbsp;Do a test print by entering the following:

<!-- CODE SNIP //-->

<PRE>

   <B>ls -l | lpr -Pmyprinter</B>

</PRE>

<!-- END CODE SNIP //-->

<DD><B>8.</B>&nbsp;&nbsp;Use the <TT>ls</TT> command to look in /tmp for a file named testlp.out. It should contain your directory listing, which you can check with the <TT>more</TT>, <TT>less</TT>, or <TT>cat</TT> command. See Chapter 17, &#147;Managing Files and Directories,&#148; for more information on these commands.

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR>&#149; <B>See</B> &#147;Viewing the Contents of a File,&#148; <B>p. 325</B><HR></FONT>

</BLOCKQUOTE>

<DD><B>9.</B>&nbsp;&nbsp;Use an ASCII editor such as <TT>vi</TT> to make the following edits to /etc/printcap:

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;In the first printer entry, change both occurrences of <TT>myprinter</TT> to <TT>testlp</TT> only in the first line.

<DD><B>&#149;</B>&nbsp;&nbsp;In the second entry, change <TT>/dev/null</TT> to your real print device&#151;for example, <TT>/dev/lp0</TT>.

<DD><B>&#149;</B>&nbsp;&nbsp;In the second entry, remove the <TT>if</TT> line completely.

</DL>

<BR>Now, copy the myprinter entry so that you have two identical entries in the file.

<DD><B>10.</B>&nbsp;&nbsp;Either reboot the system or kill the printer daemon and restart it. You do this because the printer daemon looks only at the /etc/printcap file when it first starts up.

<DD><B>11.</B>&nbsp;&nbsp;Run a test print again using the command <TT>ls -l | lpr -Pmyprinter</TT>. This one should come out on your physical printer.

</DL>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TROUBLESHOOTING:&nbsp;&nbsp;</B><BR><B>I get a message saying <TT>lpd: connect: No such file or directory.</TT></B> The printer daemon <TT>/etc/lpd</TT> isn&#146;t running. You may have forgotten to add it to your /etc/rc.local file. Or maybe you did add it but you haven&#146;t booted since then. Add it and reboot, or just run <TT>/etc/lpd</TT>. Remember that you have to be root to do this.

<P><B>I get a message saying <TT>Job queued, but cannot start daemon.</TT></B> This often appears right after the <TT>lpd: connect</TT> message; same problem as the preceding.</P>

<P><B>I get a message saying <TT>lpd: cannot create spooldir/.seq.</B></TT> You haven&#146;t created the spool directory specified in the printcap entry, or you&#146;ve misnamed it. An alternative (though much less likely) answer is that you have too little disk space left.</P>

<P><B>I get a message saying <TT>lpr: Printer queue is disabled.</B></TT> As root, use <TT>lpc</TT> enable <I><TT>printer-name</TT></I> to enable the printer. Note that as root, you can submit jobs even to a disabled printer.</P>

<P><B>I submit a print job and there are no error messages, but nothing comes out on the physical printer.</B> There could be many reasons:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;Make sure that the physical printer is switched on, selected, and physically connected to the device specified in the /etc/printcap file.

<DD><B>&#149;</B>&nbsp;&nbsp;Use the <TT>lpq</TT> command to see whether the entry is in the queue. If it is, the device may be busy, the printer may be down, or there may be an error on the printer. If there are errors, check the error log specified in the printcap entry for clues.

<DD><B>&#149;</B>&nbsp;&nbsp;You can use the <TT>lpc status</TT> command to check whether the printer is down, and you can use <TT>lpc up <I>printer-name</I> or lpc restart <I>printer-name</I></TT> to bring it back up if it is (you need to be root to do this).

</DL>

<P>If, after checking, your print jobs still don&#146;t come out, make sure that any input filter you&#146;ve specified is present in the correct directory and has the correct permissions. If you&#146;re running <TT>syslogd</TT>, you can look in your logs for messages from <TT>lpd</TT>. If you see log entries saying <TT>cannot execv name of input filter</TT>, this is almost certainly the problem.</P>

<P>Another possibility is that your printer is a PostScript printer and you&#146;re not sending PostScript to it. Most PostScript printers ignore non-PostScript data. You may need to install an appropriate text-to-PostScript input filter.</P>

<P>Last (and you&#146;ll feel silly if this is the cause), make sure that your input filter actually generates output and that the output device isn&#146;t /dev/null.</P>

<P><B>My printer seems to have locked up. None of the preceding techniques seems to solve the problem.</B> When all else fails in the case of a nonprinting printer, the next-to-last resort is to kill the <TT>lpd</TT> daemon and restart it. If that doesn&#146;t work, the last resort is to reboot your Linux system with the <TT>shutdown -r now</TT> command. Make sure that no one else is logged in and that you&#146;ve saved any files before using the <TT>now</TT> option; otherwise, specify a time and also give a message to your other users before shutting down the system. You also can test the printer on a DOS or Windows machine to make sure that the physical device itself is working.<HR></FONT>

</BLOCKQUOTE>

</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="410-412.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="416-420.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 + -