Unix/Linux PrintingThere are two ways of setting up a print server on Unix or Linux computers. This is because there are two major types of Unix, which is where TCP/IP printing was first used. In the following sections you will learn about how to configure printers for Unix/Linux computers, using
The BSD Spooling System: lpr and lpdIn BSD printing, the user sends files to print by using the line printer remote (lpr) utility; the line printer daemon (lpd) handles the details needed to get the data in the file formatted and sent to the physical output print device. To set up a printer on a Unix/Linux system that uses lpr/lpd, you need to do several things. How you accomplish them depends on your particular brand of Unix (or Linux) and whether the vendor has supplied script files or applications to help automate the process. These are the basic actions you need to take to configure a print server that will use lpr/lpd:
Tip The steps described to set up lpr/lpd printing are given here so that you can understand how to configure Unix/Linux systems to interact with printers. However, as Unix and Linux are becoming more popular alternatives to Windows and other operating systems, setting up printers has also become a much easier process. For example, Red Hat Linux (as well as other flavors of Linux) can usually detect when a new printer has been connected to the system and load the appropriate drivers and configure the printer automaticallyjust as most Windows operating systems can. Yet if you are a network administrator, trying to solve a printing problem, you should be familiar with the files, devices, and other configurable aspects of printing under Unix/Linux. To create the special device file, use the command /dev/makedev port. The port should be the port on the server to which the printer is attached. Typically, the parallel ports are named lptn (that is, lpt1, lpt2...). If the printer is connected to a serial port, the name of the port probably will be in the form of ttynn (that is, tty01, tty02...). Check your system documentation to make sure you have the correct port name. Depending on the system, you might also have to make further adjustments to configure the port, such as setting the speed. Tip After you have attached a printer and configured the port, you can use the lptest command to send a simple stream of ASCII characters to the port. This confirms whether you have been successful up to this point. You also can use this command when a printer suddenly stops printing to test simple connectivity. If the printer had been functioning normally but stops unexpectedly, and lptest does not succeed, you might want to check the cabling or fault lights on the printer itself. To create the spool directory, use the mkdir command. The spooling directory usually is created under the /var/spool/lpd directory. After you create a directory for the printer, use the chmod, chgrp, and chown commands to set the proper ownership and permission mode (for the lpd daemon). For example: # cd /var/spool/lpd # mkdir laser1 # chmod 775 laser1 # chgrp daemon laser1 # chown daemon laser1 The lpr command is used for printing files in the BSD system. The syntax for this command is lpr [-parameters][filename...] Everything but the command itself is optional. You can specify one or more files, but if you do not specify a filename, the text to be printed comes from standard input. Depending on how your particular Unix vendor has implemented the command, you have a lot of options to choose from, including these:
Tip A burst page or banner page, sometimes called a separator page, refers to a page that is printed at the beginning or end of a print job and is used to separate one user's print job from the next. In a high-volume printing environment, these pages make it easier to identify print jobs so that they can be distributed to the appropriate user. This extensive list of parameters is shown here to make the point that the lpr/lpd printing system is highly configurable from the network administrator's point of view. It might look more complex at first glance than it actually is. For example, the command lpr Phplj1 letter01.txt report.txt is all you need to use to send the files letter01.txt and report.txt to a printer named hplj1. In most circumstances, the user will not use a large subset of these parameters, but only a smaller combination that fits his work environment. Many of these parameters have default values. For example, if the printer is not specified by using the -P parameter, the Unix environment variable PRINTER will be evaluated and used for the destination of the print job. After the lpr command has determined the printer to which the data will be sent, it scans the /etc/printcap file to get information about the printer, such as the spooling directory path. It then creates several temporary files and notifies the lpd daemon that the file is ready to print. The lpd Daemon Controls the Printing ProcessThe lpr command creates a data file in the spooling directory associated with the printer and a control file that contains information telling the lpd daemon how the file should be printed. This daemon process usually starts up when the system boots by commands found in one of the rc files. However, when troubleshooting printing problems, it's often necessary to kill the lpd daemon process and restart it. The syntax for restarting the daemon is lpd [-l] [-Llogfile] [port#] The -l parameter tells the daemon to record valid network requests in a log file. The uppercase parameter -L is used to specify the name of the logfile. The port# parameter is used to specify the Internet port number the daemon will use for process-to-process communications. When the daemon first starts, it reads the /etc/printcap file to obtain information about the printers it can use. If any print jobs are outstanding from the time it was last running, the daemon begins to print them after it reads the printcap file. When it needs to actually print a file, the lpd daemon first checks to see whether another lpd daemon process is currently processing print jobs for that particular printer. If so, it passes the print job to that daemon. If not, the lpd daemon spawns a copy of itself for the printer destination, and that process continues to process jobs for the printer. The original lpd daemon that starts at boot time continues to listen for print requests and spawn new copies of itself when needed. A spawned copy of the daemon continues to run until there are no more files to print on the printer it was invoked to handle. The lpd daemon and its spawned copies control the printing process but do not perform the mechanics needed to get the data to the printer. Instead, the lpd daemon runs a filter program that sends the data to the printer, and optionally does some formatting that is needed to make the data compatible with the specific printer. Caution In a multiuser environment a locking mechanism can be used to prevent multiple processes from trying to access the same resource at the same time. When a new lpd daemon is spawned to perform print-processing functions, it creates a lock file (by using the Unix system call flock) in the spooling directory. This lock file remains in the directory while this particular lpd daemon processes files to prevent other lpd daemons from being spawned for the particular directory. The lock file is a simple ASCII file that contains the process ID (PID) of the current lpd daemon and the name of the control file for the current print job. When troubleshooting lpd daemons, you can examine the lock file to determine whether the daemon listed there is still running. In some versions of Unix, the second line of the lock file also shows the status of the current job as the daemon believes it to be. In some other versions, a file named status is used for this purpose. The /etc/printcap Configuration FileWhen you set up printing on a Unix computer that uses lpr/lpd, you must create the /etc/printcap file. Keep a written log listing changes as you make them to this file so that if something suddenly goes wrong with a printer that has been working just fine, you can check the log to determine whether anyone has recently made a change to the entry in the printcap file for the troublesome printer. This file is not a user-friendly file. In many cases, the syntax for each entry is just a few lines, but for complicated setups, editing this file can become confusing if you make changes infrequently. Tip Because the printcap file is itself a simple ASCII text file, you can make recovering from configuration issues easier by simply printing the file itself each time you make a change (or copying to a different filename, such as printcap.sav). In this manner, you can keep track of modifications to the file and have a back-out plan. And, if you ever have a problem, you can look at the changes that have been made and then make the appropriate corrections to the printcap file. Entries in this file specify the name used for a printer along with two-character symbol/value pairs (symbol=value) that define the characteristics for the printer. The printer can have multiple names (aliases), which are separated by a vertical-bar character. For example, an entry for a printer named laser could be as simple as this: laser|laser1|lp|lp0|HP Laser Jet Accounting:\ :sd=/var/spool/lpd/laser:\ :lp=/dev/tty01: The first line contains the name of the printer (laser), followed by several alias names that users can use to access the printer. The last alias on the first line shows a common technique used by many administrators: Describe the printer and/or its location. You also can put comments into the /etc/printcap file by using the pound-sign character (#) as the first character in the line. In this example, you also can see that the colon character (:) is used to separate the symbol/value pairs from each other. Although only one colon character is needed between each pair, it's customary to put one at the beginning of a line and one at the end of the line when the entry spans multiple lines. The following two entries are equivalent: :sd=/var/spool/lpd/laser1:br#9600: :sd=/var/spool/lpd/laser1:\ :br#9600: Note that the backslash character (\) is used to indicate continuation of the entry across multiple lines. Also, some entries in the file do not have a value. For example, some are Boolean entries that have no associated value and are activated by their presence in the file. In these examples, the sd symbol is followed by a directory path. This specifies the spooling directory that lpd will use to store files that are waiting to be printed. Multiple users can send files to the printer using the lpr command. Copies of the files to be printed are created by the lpd daemon in the spooling directory and remain there until they are printed. After a file has been printed, the lpd daemon deletes the control and data files used for it. The lp symbol is used to indicate the special device file for the printer. In Unix, device files are used as a link to a physical device. The makdev command is used to create the device file just as for any other device attached to the computer. However, in the case of a remote printer, use the hostname/queue name on the remote system for this value instead of a device filename. Entries can be much more complex than in this simple example. Table 41.1 lists the symbols you can use to customize a printer.
Following is an example of a more complicated entry: lp|lp0|Color Laser: \ :af=/usr/adm/printer/clp.acct:\ :br#9600:\ :lf=/usr/adm/lpterror:\ :lp=/dev/tty05:\ :mx#0:\ :sd=/var/spool/lpd:\ This example defines the spooling directory for a printer, as well as the logfile and accounting file. The mx#0 entry means there is no maximum size limit for files that can print on this printer. When specifying a printer device, you also can tell the lpd daemon to use a print queue that resides on another system. For example: xprint|laser2|Manufacturing printer:\ :lp=:\ :rm=mfgunix:\ :rp=lp:\ :sd=/var/spool/lpd/xprint:\ :mx#0:\ In this example, the lp symbol is set to null. This indicates that the print device is not on this system. You still have to include the lp symbol so that the default value for it will not be substituted by the lpd daemon. The rm symbol is used to indicate the hostname of the remote computer, and the rp symbol is used to define the name of the printer on that system. Also, even though the actual printing is done on the remote computer, you must specify a spooling directory because files submitted to the queue still need to be temporarily stored before they are copied to the remote system. Useful Commands: lpq, lprm, and lpcFrom the user's perspective, printing is a simple task. Just use the lpr command and wait for the paper to come out of the printer. As the administrator, you need commands that can help you manage print queues and track usage. The lpq command shows information about jobs waiting in the print queue. The information this command shows you includes the following:
For example: Rank Owner Job Files Total Size active ogletree 133 prm0d1x 31540 bytes 1st heywood 141 letter1 3423 bytes 2nd chasog 216 jandata 98465 bytes 3rd peter 323 twoinchtml 2342 bytes 4th menton 122 queulst 55432 bytes You can use the -P parameter to specify the printer just like you can with the lpr command. Similarly, the Unix environment variable PRINTER determines the printer to display if you do not specify one. The syntax for the lpq command is as follows: lpq [-Pprinter][-l][+[interval]][job#...][username...] The -l parameter causes a "long" listing (more output, additional information) to be displayed. The plus sign (+) can be used by itself or with a numeric value, and it causes the command to continuously display the status until the print queue empties. If you follow the plus sign with a numeric value, it is used as the number of seconds between each refresh interval. Use the job ID numbers or the user's username when troubleshooting specific print jobs so that you won't have to look through a long listing of all print jobs. The job ID number also can be used by other print-queue management commands, so it is common to use lpq to get a job's ID number before executing other commands. To remove a print job from the queue, you can use the lprm command. Its syntax is similar to the lpq command: lprm [-Pprinter][-][job#...][username...] Although any user can remove her own files that are pending in a print queue, only the superuser (root account) can remove other users' files. You can specify the job ID number associated with a specific file, or you can specify a username to remove all print jobs currently pending in the queue for that user. Note To remove jobs from a print queue, the lprm command actually kills the current lpd daemon that is processing files for that queue. It then deletes the specific files from the print queue and restarts a new daemon process to continue processing the remaining files. Examining a print queue and removing pending jobs can be useful for troubleshooting simple problems. For more control over the BSD printing system, you can use the lpc (line printer control) command. The syntax for this command is more complicated than that of the lpq and lprm commands because of the more complex functions it can perform. The syntax for lpc is as follows: lpc [command [parameters...]] These are the commands you can use with lpc:
Although the lpc program usually is used by an administrator (the root user account, sometimes referred to as the superuser account), ordinary users can use the restart and status commands. The following is an example of using the lpc command to get the status of a printer named laser1. In this example, the queue is enabled and printing. Only one job is in the queue. When you use the command without command-line parameters, it prompts you in interactive mode: % /usr/sbin/lpc lpc> status laser2 laser1: printer is on device '/dev/tty03' speed 9600 queuing is enabled printing is enabled 1 entry in spool area lpc>quit In this next example, the lpd daemon for this queue has exited unexpectedly. Using the lpc command, you can detect this condition and fix the problem: % /usr/sbin/lpc lpc> status laser2 laser2: printer is on device '/dev/tty03' speed 9600 queuing is enabled printing is enabled 7 entries in spool area no daemon present lpc> restart laser2 lpc>quit Examining Printing StatisticsPart of managing a network is gathering statistics. This is done for several reasons. First, historical data is nice to have when you are trying to determine the circumstances leading up to a problem. Second, statistical data can help you plan for enough capacity when you are deciding on expansion or reorganization. Another use for the information is user or department accountability. In environments where costs are charged back to a department, you can use the pac command to gather the data you need. The syntax for this command is pac [-Pprinter][-cmrs][-pprice][username] As is the custom with other printing commands, the -P parameter allows you to specify a printer. If you do not, the value of PRINTER is used; otherwise, the system default printer is assumed. These are the other parameters you can use:
Tip You can include the pac command in script files to create automated procedures to produce accounting reports. For example, you could use a script file to produce reports by user or department, and then email a copy of the report to a responsible person. The following output shows the type of information you can get by using the pac command. The costs for each print job are just simple calculations based on the unit and the cost you supply to the command, as the following illustrates: Login pages/feet runs price atlunix1:harris 14.00 1 $ 0.28 atlunix1:brown 3.00 2 $ 0.06 pluto:ogletree 21.00 3 $ 0.42 The SVR4 Printing SystemAnother major type of Unix variant is the System V, Version 4 (SVR4) system. The SVR4 printing system uses the lp command and lpsched command to print and manage printer queues. Although an /etc/printcap file also is used, it doesn't have to be edited manually. The lpadmin utility will do this for you. Using lp, cancel, and lpstatThe lp command is used just like the lpr command. However, the lp command does more than just send files to a printer; it also can be used to modify print jobs. The cancel command is used to remove a job from the print queue. The syntax for the lp command comes in two different forms: lp [-c][-m][-p][-s][-w][-d dest] [-f form-name [-d any]][-H special-handling] [-n number][-o option][-P page-list] [-q priority-level][-S character-set][-d any]] [-S print-wheel[-d any]][-t title] [-T content-type][-r]][-y mode-list] [filename...] lp i request-id ... [-c][-m][-p][-s][-w] [-d dest][-f form-name[-d any]] [-H special-handling][-n number][-o option] [-P page-list][-q priority-level] [-S character-set[-d any]]] [-t title][-T content-type[-r]] [-y mode-list] The first version of this command is used to send files to print. The second version is used to modify a print request that is already pending. If you use the second version to modify a job that is already printing, it stops the job and restarts it with the changes you have made. These are the parameters you can use with the lp command:
Terms you can use for the option are listed here:
If you need to simply stop a job from printing, you can use the cancel command. These are the syntax alternatives for the cancel command: cancel [request-id...][printer...] cancel u login-ID-list [printer...] The first syntax example can be used to remove a specific print job by specifying its ID number. The second example shows how to remove all print jobs for a particular user (or users). If you list multiple users on the command line, enclose the list in quotes and use a space between each ID name. Ordinary users can cancel only their own print requests. Administrators can cancel any print job. To get the request-id of a print job, you need to use the lpstat command. This command can be used by ordinary users with no parameters and will return information about only their print jobs. However, the administrator can use this command to see data about the entire printing system. The syntax for lpstat is as follows: lpstat [-d] [-r] [-R] [-s] [-t] [-a [list]] [-c [list]] [-o [list]] [-p [list]] [-P] [-s [list] [-l]] [-u [login-ID-list]] [-v [list]] In this example, list can be a comma-delimited list or a series of items separated by spaces and enclosed in quotes. You can omit a list or use the keyword all in most instances to get the status of all the requested objects. These are the parameters for this command:
Administering the System: lpadmin, lpsched, and lpshutThe lpadmin command performs a wide range of functions necessary to set up a printer on a Unix system. The command adds, removes, or modifies printers, and creates the necessary text files in the spooling directory for you so that you don't have to edit them manually. This command also can be used to set up "alerts" when the printer experiences a fault condition. The syntax for this administrative command is lpadmin -p printer-options lpadmin -x dest lpadmin -d [dest] lpadmin -S print-wheel -A alert-type [-W minutes] [-Q requests] lpadmin -M -f form-name [-a [-o filebreak] [-t tray-number] The first line of this syntax example shows how to add a new printer. Use the -p option on the command line to specify the printer's name and then list the printer's characteristics. For example: lpadmin phplj5 v/dev/tty03 mdumb -cpr This command performs the functions needed to create a printer named hplj5. Following the printer name, the options here indicate that the actual printer device is connected to a serial port that can be accessed through the Unix device file /dev/tty03. This printer uses a dumb interface (-m option) and is a member of a class of printers named pr (the -c option). As explained later, the m option is used to specify an interface program used to interact with a particular printer model. In the preceding example, dumb refers to a generic line printer. The file /usr/spool/lp/model contains other model interface programs, and you can view this file to see which printer models are supported on your system. Tip After you set up a printer using lpadmin, it does not automatically allow users to print. Use the accept printer command to enable printing. The man pages for your system give you a full list of the options you can use on the command line, and they vary depending on the flavor of Unix you have. However, the following list shows some of the more useful ones you'll find on most systems:
Tip Unix and Linux commands can be complex and difficult to remember. Both of these operating systems use "man" pages (which stands for manual) that are basically help files. You can consult them when you need help for a particular topic. For example, the command man lpadmin can be used to get the help text for the lpadmin command on the system so that you can see a full list of the options supported. To remove a printer from the LP printing system, use the -x command-line parameter: lpadmin xhplj5 This command removes the hplj5 printer from the system. If this is the last printer in its class of printers, the printer class also is deleted. In the /etc/init.d/lp file, you will find commands that can be used to start the print scheduler daemon at boot time. The syntax, in case you want to change the boot-time command, is lpsched [-nofork][-debug][-nobsd] You also can use this command to restart the daemon if you find it necessary to kill it when you are troubleshooting printer problems. The lpsched daemon works sort of like the lpr daemonit creates a new copy of itself to handle print jobs. The original daemon remains free to respond to additional user requests. Note The -nofork parameter can be used to suppress the creation of a separate daemon process. This is recommended to be used during debugging. You also can use the -debug parameter to put the daemon into "verbose" mode. In this mode, more messages are displayed that can be useful when trying to solve printer problems. The -nobsd parameter can be used to tell lpsched to ignore the BSD spooler's well-known port. If you also are running an lpd daemon on the system and it is using the default port, use this option to change the port used by lpsched. Tip "Well-known ports" are IP port numbers from 0 to 1024. These are generally assigned to system processes that operate using privileges that the ordinary user does not have. A port is used by TCP and UDP to specify an endpoint that an application can use, along with an IP address. This combination of IP address and port number can uniquely identify both endpoints for exchanging data using the TCP/IP protocol suite. In essence, the IP address gets the network packets to the correct computer (or other hardware device), and the port number specifies a process (such as a background daemon process) that is listening for incoming requests that use the port number assigned to the process or daemon. For example, the basic FTP protocol uses ports 20 and 21, and the basic Telnet daemon uses ports 23 and 24. Ports above 1024 have been assigned to various applications, many of which are now extinct. However, it is important that you understand that port numbers 1024 and below should be used only by applications or utilities that can perform actions an ordinary user cannot. You can use several commands to shut down a printer, depending on just what you need to do:
If a printer will be out of service for a while, and you don't want users to keep submitting jobs, use the reject command. If a printer is going to be taken out of service completely, use the lpadmin command to remove it. If some major problem is plaguing your entire printing system, use the lpshut command to bring everything to a halt while you investigate the problem. One last command that might be handy when performing troubleshooting or maintenance duties is the lpmove command. This command can move pending print requests from one printer to another. For example: lpmove hplj5 221 hplj5land 232 laser3 In this example, the print job identified by the request-id number 221 will be moved from the hplj5 printer to laser3. The print job identified by the request-id 232 waiting for hplj5land also will be moved to laser3. Note Common Unix Printing System (CUPS) is an open source Unix/Linux based printing solution. CUPS is a freely distributable collection of tools and drivers that allows host systems to control printer devices, manage print queues, and process print requests. CUPS provides a portable printing layer for UNIX-based operating systems. It has been developed by Easy Software Products to promote a standard printing solution for all UNIX vendors and users. CUPS provides the System V and Berkeley command-line interfaces. For more information about CUPS, visit http://www.cups.org/ |