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

📄 lsg19.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<PRE>







<FONT COLOR="#000080">lpd [-l] [port]</FONT></PRE>







<P>The -l option starts a logging process that copies a note to a log file every time a print request is handled. Although the -l option can be useful when you're debugging a printer installation or configuration, be careful about leaving it running for too long&#151;the log files tend to become very large. If you do keep logging active, use a cron process to clean the log file at regular intervals.







<BR>







<P>The port option of the lpd command enables you to specify an Internet port number for the daemon if you want the system default information to be ignored. You will probably never have to use this option on a stand-alone or small network, but it can be useful with very large networked printing systems (which are unlikely to be based on Linux).







<BR>







<P>When a print request is received over the network (or locally), the lpd daemon performs a short validation routine to see whether the user who sent the request is allowed to use the printer. This routine uses the /etc/hosts.equiv and /etc/hosts.lpd files. If the machine name of the sending user is not in either file, the print request is refused. Your local machine is always in hosts.equiv (as localhost), so all users on your machine can have their print requests granted.







<BR>







<P>If you have to terminate the lpd daemon, obtain its process ID number using the ps command, and then issue a kill command with that process number. <A HREF="lsg20.htm">Chapter 20</A>, &quot;Processes,&quot; explains these steps in more detail. When the lpd daemon is terminated, no print requests are accepted.







<BR>







<BR>







<A NAME="E69E135"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Print Spoolers</B></FONT></CENTER></H4>







<BR>







<P>When a print request (often called a print job) is received by lpd (or its associated listen and accept processes), the pages to be printed are copied to another area, called the print spool area, of the filesystem. This action frees up your console when you issue a print request and enables you to continue to make changes to the files you want to print after they have been sent to the daemon.







<BR>







<P>In most cases, the print spool area is in the /usr/spool/lp directory. Under this spool directory, each installed printer has a dedicated directory, which is usually given the printer's name specified during the printer installation routine. For example, a printer called hplaser uses the spool directory /usr/spool/hplaser. All the print requests for each printer are stored in its directory. In this directory, each request is assigned a unique filename and a print request identification number. The daemon for this printer adds the print request number to a queue and notifies you of what the number is. You can then use the print request identification number to check the status of the print request or remove the request from the queue.







<BR>







<P>Some versions of Linux let you set the size of the print spool area though an entry in the minfree file in the spool directory. The minfree file gives the number of disk blocks (usually a block is 1K) set aside for spooling requests. You can change the minfree file with any ASCII editor. If you have lots of disk space, you needn't worry about this value because the spooler will use available space as necessary. If you are tight for disk space, though, you may want to reserve a little space for the spooler that can't be used for other reasons. The size of the disk space reserved for the spooler should be dependent on the number of users and the amount of printing they will do. A good rule of thumb is about 100K per user for normal use.







<BR>







<P>Each printer's spool directory may contain two special files called status and lock. Each file is one line long and can be modified with an ASCII editor. The files contain a description of the current state of the printer. The lpd daemon creates and manages these files, which several printer commands use display status information to the user.







<BR>







<BR>







<A NAME="E69E136"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>The Printing Process</B></FONT></CENTER></H4>







<BR>







<P>This section follows a typical print request through the print system so you can see how the printer daemons work and how Linux handles each stage of the request. When you issue a print request with a print command (such as lpr), the command generates output for the printer to print. The command then copies that output into the queue in the spool directory for the printer you have requested.







<BR>







<P>You can specify the printer destination on the print command line or set a default printer name as an environment variable so the system always knows which printer to use. After determining the destination printer name, lpr checks the file /etc/printcap for the printer's configuration information (including the spool directory name).







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>The lpr program is the only one in the Linux system that can queue files for printing. Any other program that offers printing capabilities, including most editors and word processors, executes the print request by calling lpr.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<P>As part of the spooling task, lpr checks for any special instructions on how to print the file. These instructions may refer to fonts, paper sizes, colors, processing languages, or any other printer configuration information. Printer instructions can come from the command line (in the form of arguments you provide with the print command), from environment variables (set up by the shell's startup files or you), or from the system's default values.







<BR>







<P>When the print request is copied into the spool directory, lpr creates two files. One file has the letters cf (control file) followed by the print ID number. This cf file contains information about the print job, including the owner's name and special printing instructions such as line spacing or paper selection. The other file starts with the letters df (data file) and holds the contents of the file to be printed. After lpr creates the df file, it sends a signal to the lpd daemon that indicates that a print job is waiting in the spool directory. The lpd daemon then starts a daemon to handle the printer's queue (if one isn't already running). A daemon is present for every printer queue as long as there is something to print. When the print queue is empty, the printer daemon terminates.







<BR>







<P>After lpd gets the print job signal from lpr, it checks the file /etc/printcap to see whether the printer is a local or remote printer. For remote printers (one attached to another machine on the network), lpd starts a network connection to the remote machine and transfers both the control and data files to the remote's spool directories and informs the remote machine's lpd daemon that a print request is queued. To end the process for a remote print request, lpd deletes the local copies of the cf and df files. For local printer requests, lpd checks to make sure the printer exists and is enabled, and then sends the print request to the daemon running that printer queue. Once the files have been printed, they are deleted from the spool directories.







<BR>







<BR>







<A NAME="E69E137"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>The /etc/printcap File</B></FONT></CENTER></H4>







<BR>







<P>As you have seen already in this section, the /etc/printcap file is used by both the print commands (such as lpr) and the lpd daemon. The /etc/printcap file contains information about every printer that is accessible from the Linux machine, including all remote printers that have been configured on the local machine. The following extract from the /etc/printcap file for the Hewlett Packard LaserJet 4M laser printer shows the straightforward format of this kind of file:







<BR>







<PRE>







<FONT COLOR="#000080"># HP Laserjet







lp|hplj|hplaserj-tparker|HP LaserJet 4M next to the water fountain:\







 :lp=/dev/lp0:\







 :sd=/usr/spool/lp/lp0:\







 :lf=/usr/spool/lp/errorlog:\







 :mx#0:\







 :of=/usr/spool/lp0/hpjlp:\</FONT></PRE>







<P>Comments anywhere in the information are identified by a pound sign (also called a hash mark) in the first column. The first field in each printer's entry is a list of all the names users can use to refer to the printer. These names can be used with environment variables and as options on the lpr command line. All the valid printer names are separated by a vertical bar. Usually each entry has at least three names: a short name that is four characters or less (such as hplj), a more complete name with an owner, if necessary (such as hplaser-tparker), and a full descriptive name with any other information necessary to identify the printer to a user (such as HP LaserJet 4M next to the water fountain).







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>If a print job is submitted without a destination name and one cannot be determined from environment variable values, the job is routed to the Linux system default printer name lp. Therefore, one of the printers (usually the system default printer) should also have the name lp as part of its identifying names in order to prevent error messages.</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<P>Following the printer name is a set of two-character parameters and values used to define configuration information about the printer. The format of these entries follows one of the following models:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







NN 







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







A Boolean value</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







NN=string







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Set equal to string</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







NN#number







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Set not equal to number</FONT>







</TABLE><P>Most assignments in this area of the /etc/printcap file are shown with colons beginning and ending each definition to enhance readability (and make the file easier for the print utilities to parse for information). Null values are allowed; you can create them by putting two colons together with no space between them.







<BR>







<P>When you use a Boolean value (with no assignment following the two character identifier), the value is set to True by default. If you want the vaule to be False, don't include the two-character identifier in the description. You use Booleans to specify simple information, such as printer control language support.







<BR>







<P>As with terminal definitions in the /etc/termcap file, many codes are allowed in the /etc/printcap file. A few of the more important and prevalent parameters are worth mentioning as they are useful for administration purposes:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







sd







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







The spool directory</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







lf







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







The log directory for error messages</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







af







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Accounting log file</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







mx







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







What type of files can be printed</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







of







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Output filter program to be used when printing</FONT>







</TABLE><P>Not all these parameters need to be present in every printer definition in the /etc/printcap file, but they are likely to be present as they provide basic information.







<BR>







<P>The sd parameter specifies the spool directory for the printer. As mentioned earlier, all printers should have their own spool directories. The spool directories are usually composed by taking the printer name and creating a directory with that name under the /usr/spool directory, such as /usr/spool/lp/hplj and /usr/spool/lp/epson. Spool directories are necessary for both remote and local printers.







<BR>







<BLOCKQUOTE>







<BLOCKQUOTE>







<HR ALIGN=CENTER>







<BR>







<NOTE>When you add a new printer is added to the system, you may have to create a spool directory manually by using mkdir. Set the permissions for the spool directory to 775. The directory must be owned by root or daemon, and you should set the group ID to root or daemon as well. In both cases, daemon is arguably the better ID for user and group, although root works fine (but may pose a very slight security problem).</NOTE>







<BR>







<HR ALIGN=CENTER>







</BLOCKQUOTE></BLOCKQUOTE>







<P>The lf parameter specifies the log directory for error messages. You can put the printer error log file anywhere on the system, although most Linux systems have it in the /usr/spool/lp directory for easy access. All printers can share the error log, as each log entry includes the name of the printer. Putting all the error messages in one directory makes it easier to clean up the log files on a regular basis.







<BR>







<P>A printer accounting log file, as specified by the parameter af, is used to record the number of printouts sent by a user on systems where users are charged for printing. When an accounting file is used, an entry is written to the accounting log file after a print job is finished. If the system doesn't use accounting records (most Linux systems don't), you can ignore the accounting log file entry in the /etc/printcap file, although you may want to have the accounting file active for statistical purposes. You can display account information with the Linux pac command. Use the man pac command to display the man pages for more information about pac.







<BR>







<P>The mx parameter enables you to identify the types of files to be printed. Usually this parameter is set to mx#0, meaning that there are no restrictions on the types of files. You may want to restrict the type of printing on some lasers or inkjets that have high per page costs, for example, or prevent pages with color instructions from being printed as grayscales on a monochrome laser printer.







<BR>







<P>You use output filters, specified by the parameter of, to modify the format of the outgoing print file to fit the printer. For example, a common output filter changes the number of lines per page. Many laser printers can't handle 66 lines per page, so the output filter repaginates output to 60 lines per page (or whatever the number of lines per page is set to). Sometimes special codes must be added to force line feeds, font changes, or paper bin selections. All these items are part of the output filter. Several other types of filters are available, but the output filter is the most common.







<BR>







<BR>







<A NAME="E68E105"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Managing Printers with lpc</B></FONT></CENTER></H3>







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -