-->
Page 233
This means that you can send documents to other printers anywhere. Using Red Hat's printtool command to set up remote printing will create a remote printer entry in /etc/printcap. For details about a remote printer entry, see the printcap man page and look for the rm and rp capabilities. But you should also know there are other, possibly easier ways to print to remote printers, such as using the rlpr command. For more information, read Grant Taylor's Linux Printing HOWTO under /usr/doc.
To set up a LAN printer, you'll need the following (according to printtool):
This information is entered in a dialog that pops up after you select the type of printer you want to set up. If you want detailed instructions on how to print from Red Hat Linux to a printer on a Windows 95 system or to print on a Linux printer from Windows 95, browse to http://www.redhat.com/support/docs/rhl/Tips.
For now, I'll assume you're going to set up a parallel port printer attached directly to your computer. To do so, run printtool, then click the Add button, select Local, and then click the OK button.
An Info dialog will appear, telling you which parallel printer devices have been detected. Click OK and then click the Select button in the Edit Local Printer Entry dialog. You'll be presented a large dialog called Configure Filter, with a list of 32 popular printers to choose from (see Figure 12.2). Pick your printer, or a printer close to yours, and then click the OK button.
The dialog will disappear, and you can then click OK on the Edit Local Printer Entry dialog. The printer you defined will appear under the list of Printer Queues in the main printtool dialog. Select it and then select an ASCII or PostScript test from the Tests menu.
The ASCII test page prints two lines of text, followed by a centered paragraph of text. The PostScript test page prints a half-inch and one-inch border, a logo, and color scale (grayscale on a black-and-white printer).
printtool works by first defining your printer and then inserting the definition, along with a pointer to a filter script (written in bash) in the /var/spool/lpd directory, into an /etc/printcap entry. The filter and associated scripts reside in a directory, or printer queue, under /var/spool/lpd, with either a name you choose, or an assigned default, such as lp0. See the sample /etc/printcap database file later in this chapter.
Page 234
You can use printtool to add, edit, or delete different printers. Another nice feature is the ability to assign a size limit to spooled files, which can be helpful if you have limited disk space or don't want users to fill up your filesystem. If you have a printer that requires you to change the print cartridge in order to print black-and-white or color pages, you'll find printtool indispensable. Try it!
By the way, although the current version of printtool, 3.2, creates a backup of your /etc/printcap database each time you make a change, it does not delete the associated printer queue, or spool directory, when you delete a printer. One disconcerting printtool bug is that while you're printing, at least with a kernel using polling, your printer's parallel port will not be detected if you run printtool to install a printer. Perhaps this will be fixed in a newer version.
Of course, you don't have to use the printtool command to set up your printer. You can edit /etc/printcap directly, but you should know what you're doing and understand printcap's format. This file, an ASCII database of your system's local and networked printers, describes the capabilities of each printer in detail. For full details, see the printcap man page for commands, and the termcap man page for the file's layout.
In fact, you can have multiple entries for each printer, which is helpful is you want to print different size papers, print color or black-and-white documents, or change printer trays.
Linux uses the 4.3BSD line printer spooling system. This system has a number of features and associated programs to support background printing, multiple local and networked printers, and control of the printers and queued documents.
The main files used in the Linux printer spooling system are as follows:
/etc/printcap /usr/sbin/lpd /usr/sbin/lpc
Page 235
/usr/bin/lpr /usr/bin/lprm /usr/bin/lpq /dev/printer
When you first boot Linux, the shell script lpd.init, under /etc/rc.d/init.d/, starts lpd, the printer daemon. This program, a printer server, runs in the background, waiting for print requests. When a request is detected (on /dev/printer), a copy of lpd is created, while the original continues to wait for more requests.
Print requests are started with the lpr command. For example, the command line
# lpr myfile.txt
will print your document to a file in the /var/spool/ directory. There are also print spooling commands to help you track your request. If you're printing a large document, or a number of smaller files, you can see a list of print jobs running by using the lpq command. For example, to print a number of files at once, use
# lpr .x*
followed by
# lpq
This outputs the following:
Rank Owner Job Files Total Size active root 301 .xboing-scores, .xinitrc 1366 bytes
If you want to stop the preceding print job, use the lprm command, followed by the job number, as in the following:
# lprm 301 dfA071Aa01088 dequeued dfB071Aa01088 dequeued cfA071Aa01088 dequeued
This shows that lprm has removed the spool files from the printer's spool directory under /var/spool/lpd.
If you want to disable or enable a printer and its spooling queue, rearrange the order of any print jobs, or find out the status of printers, you can use lpc from the command line or interactively. But you must be logged in as root or as a superuser (through the su command). See the lpc man page for details.
Of course, printing directory listings or short text files is fine, but default printouts of longer files require formatting with borders, headers, and footers. To get a nicer document with text files, use the pr command.