UNIX System Administration Handbook - Evi Nemeth [419]
When the job is ready to print, lpd creates a series of UNIX pipes between the spool file and the printing hardware through which the data to be printed is transported. In the middle of this channel lpd installs a filter process that can review and edit the contents of the data stream before it reaches the printer.
Filter processes can perform various transformations on the data or do nothing at all. Their chief purposes are to provide formatting and to support any device-specific protocols that may be required for dealing with a particular printer. A printer’s default filter is specified in /etc/printcap, but the default filter can be overridden on the lpr command line.
Controlling the printing environment
For day-to-day maintenance of the printing system, you need only three commands: lpq, lprm, and lpc. lpq examines the queue of jobs waiting to be printed on a particular printer. lprm deletes one or more of these jobs, erasing their stored data files and removing any references to them from within the printing system. Both of these commands are available to users, and both work across a network (if you’re lucky).
lpc lets you make a number of changes to the printing environment, such as disabling printers and reordering print queues. Although some of its functions are available to users, lpc is primarily an administrative tool. Table 23.1 shows some other commands and daemons associated with the BSD print system.
Table 23.1 BSD printing commands
lpd: the BSD print spooler
When lpd first starts, it reads the /etc/printcap file, in which the system’s printers are defined. It then starts printing any jobs that are waiting in the spool directory and starts listening for new print requests.
If you start lpd with the -l flag, it logs print requests through syslog under the “lpr” facility. Without the -l flag, lpd logs only printing system errors.
Access control is defined for each host; the BSD printing system cannot support access control for specific remote users.2
Only hosts whose names appear in the files /etc/hosts.equiv or /etc/hosts.lpd are allowed to spool print jobs. Remember that adding a hostname to /etc/hosts.equiv indicates complete trust of that host. We recommend that you stick to the /etc/hosts.lpd file for printer access control. If you require a finer-grained security model, consider switching to LPRng.
See page 660 for more information about the hosts.equiv file.
lpr: submit print jobs
lpr is the only program on a BSD system that can queue files for printing. Other programs that cause files to be printed (for example, enscript and netscape) must do so by calling lpr.
Several useful options can be specified as arguments to lpr. The -#num flag produces num copies, and the -h flag suppresses the header page. Reminiscent of the days of slow printers, the -m flag requests that email be sent to the owner when the print job is complete.
For example, to print two copies of a file named thesis to a printer called howler-lw, you could type
% lpr -Phowler-lw -#2 thesis
lpq: view the printing queue
lpq is normally used with just a -P option to select a printer, although the -l flag is available to produce more detailed output. Output from lpq looks like this:
% lpq
anchor-lj is ready and printing
Rank Owner Job Files Total Size
active garth 314 domain.2x1.ps 298778 bytes
1st kingery 286 standard input 17691 bytes
2nd evi 12 appendices 828 bytes
3rd garth 13 proc 43229 bytes
4th scott 14 periodic 16676 bytes
5th garth 16 standard input 489 bytes
The first column tells you the order in which the jobs will be printed. This information is rather superfluous because the output lines are always in order, with the active job on top and the last job to be printed on the bottom. If the first job is listed as 1st rather than active, no printing daemon is running on the printer.
The second column tells you which user spooled each job. The third column gives the job identification