UnixLinux Printing


Unix/Linux Printing

There 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 lpd

  • The SVR4 Printing System

The BSD Spooling System: lpr and lpd

In 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:

  • Physically connect the printer to a port on the server computer or print server or, alternatively, configure a network printer with a TCP/IP address so that you can direct print jobs to it.

  • Create a special device file that Unix (and most Linux OSs) use to reference devices if the printer is connected physically to the computer.

  • Create entries in the printer configuration file ( /etc/printcap ) that describe the characteristics of this printer, along with management items such as accounting or log files.

  • Create the directories that will be used to store files while they are waiting to print (spooling directory).

  • Place commands in the appropriate Unix startup file ( rc file) to start the lpd daemon when the system boots.

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 automatically ”just 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 lpt n (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 tty nn (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:

  • # ” Specifies the number of copies to print.

  • c ” The date file(s) to be printed were created by the cifplot filter.

  • C ” Text following the C ("Job Classification") character is printed on the burst page for the print job.

  • d ” Indicates that the data file(s) to be printed contain data created by the tex command.

  • f ” Printing FORTRAN files. The first character in each line is interpreted as a FORTRAN carriage control character.

  • g ” The data file(s) to be printed contain data created by a program using the standard plot routines.

  • h ” Suppresses printing the burst page.

  • i Indent value ” If a job is printed with an indent of 8 spaces by default, you can change it with this parameter. This value is passed to the Unix input filter, which does the actual formatting of the data to be printed.

  • J Job ” Text following the J character is printed on the burst page for the print job. If this parameter is not used, the name of the first file on the print command line is used on the burst page.

  • l ” Control characters are printed and page breaks suppressed.

  • m ” Send a mail message after the job is printed.

  • n ” The data file(s) to be printed contain data created by the ditroff command.

  • p ” Uses the pr command as the filter to process the print job.

  • P ” Name of the destination printer.

  • r ” Removes the file when spooling (or printing using the -s parameter).

  • s ” Indicates that the file should not be spooled. Instead, a symbolic link is used. This is a good option to use when printing large files, or a large number of files, to minimize consumption of disk space.

  • T Title ” Used with the -p option, which causes the pr command to be used to format the file to be printed. Text specified with this parameter is passed to pr . If blank spaces or special characters are used, the text should be enclosed by single quotes ( ' ' ).

  • t ” Indicates that the data file(s) to be printed contain binary data created by the troff command.

  • v ” The data file(s) to be printed are in raster image format.

  • w ” Number of columns . This parameter specifies the number of characters on the page (width).

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 Process

The 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] [-L  logfile  ] [  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 File

When 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:

 laserlaser1lplp0HP 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 45.1 lists the symbols you can use to customize a printer.

Table 45.1. Symbols Used in the /etc/printcap File

Symbol

Type

Default Value

Description

af

string

NULL

Name of accounting file.

br

numeric

no default

Baud rate if lp is a tty.

cf

string

NULL

The cifplot data filter.

df

string

NULL

The TeX data filter (DVI format).

du

string

no default

Used to specify a nonstandard user ID for the daemon.

fc

numeric

If lp is a tty, clear flag bits.

ff

string

/f

String to send to printer for form feed.

fo

Boolean

false

Print a form feed when device is opened.

fs

numeric

If lp is a tty, set flag bits.

gf

string

NULL

Graph data filter (plot format).

hl

Boolean

false

Print the burst header page last.

ic

Boolean

false

Driver supports (nonstandard) ioctl to indent on printout.

if

string

NULL

Accounting text filter.

lf

string

/dev/console

Name of error logging file.

lo

string

lock

Name of lock file.

lp

string

/dev/lp

Output device.

mc

numeric

Maximum number of copies allowed.

mx

numeric

1000

Maximum file size (in BUFSIZ blocks) ”zero means unlimited.

nf

string

NULL

The ditroff data filter (device independent troff).

of

string

NULL

Output filtering program.

pc

numeric

200

Price per foot or page (in hundredths of cents ).

pl

numeric

66

Page length in lines.

pw

numeric

132

Page width in characters.

px

numeric

Page width in pixels (horizontal).

py

numeric

Page length in pixels (vertical).

rf

string

NULL

The FORTRAN-style text file filter.

rg

string

NULL

Restricted group . Only members of this group are allowed access to the printer.

rm

string

NULL

Machine name for remote printer.

rp

string

lp

Remote printer name argument.

rs

Boolean

false

Restrict remote users to only those who have local accounts.

rw

Boolean

false

Open the print device for read/write.

sb

Boolean

false

Short (one-line) banner.

sc

Boolean

false

Suppress multiple copies.

sd

string

/usr/spool/lpd

or

/var/spool/lpd

Spooling directory.

sf

Boolean

false

Suppress form feeds.

sh

Boolean

false

Suppress printing of burst page header.

st

string

status

Name of status file.

tf

string

NULL

Name of troff data filter (cat phototypesetter).

tr

string

NULL

Trailer string to print when queue is emptied (that is, form feeds or escape characters).

vf

string

NULL

Raster image filter.

xc

numeric

If lp is a tty, clear local mode bits.

xs

numeric

If lp is a tty, set local mode bits.

Following is an example of a more complicated entry:

 lplp0Color 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:

 xprintlaser2Manufacturing 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 lpc

From 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:

  • The order of print jobs in the queue

  • The name of the user who submitted the job to print

  • The job identification number

  • The names of files waiting to print

  • The size of the print job (in bytes)

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 [-P  printer  ][-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 [-P  printer  ][-][  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 :

  • abort [all printer ...] ” Kills the active lpd daemon and then disables printing for the specified printers. Stops the print job that is currently printing. After this, lpr will not be able to create a new lpd daemon for the specified printers. Use this option when you need to quickly disable a printer.

  • clean [all printer ...] ” Removes temporary files (including control and data files) from the specified printer's spooling directory when the files do not form a complete print job. Useful for "cleaning up" a spool directory when something has gone wrong.

  • disable [all printer ...] ” Prevents lpr from submitting new print jobs to this print queue. This command turns off printing for the specified queue.

  • down [all printer ...] message ... ” Turns off the print queue and disables printing. Message... text is entered into the status file for the printer so that lpq can report it.

  • enable [all printer ...] ” Enables spooling on the printer(s) so that users can begin to use the lpr command to submit print jobs.

  • restart [all printer ...] ” Starts a new daemon for the queue. When a printer daemon dies unexpectedly, you can use this command. The jobs currently existing in the queue are printed by the new daemon. You should perform this command when the lpq command gives you the no daemon present message.

  • start [all printer ...] ” Enables printing and starts a spooling daemon for the printers specified. Changes the owner's execute permission on the lock file to accomplish their tasks .

  • status [all printer ...] ” Gets the status of printer daemons and queues. Shows whether the queue is enabled or disabled, or whether printing is enabled or disabled. Also shows the number of entries in the queue and the status of the printer's lpd daemon.

  • stop [all printer ...] ” Stops a spooling daemon and disables printing. The daemon stops after it finishes the current print job. Use the abort command if you want to stop the daemon and kill the current job that is printing.

  • topq printer [ job# .. .][ username ...] ” Moves print jobs to the top of the queue. Use this to bypass the normal first-in, first-out (FIFO) order of printing. Specify one or more job numbers as an argument to this command. Specify a username as the argument to move all jobs pending for that user to the top of the queue.

  • up [all printer ...] ” Enables all printing and starts a new printer daemon. Opposite of the down command.

  • exit or quit ” Causes the lpc program to exit (when in interactive mode).

  • ? [ command ] or help [ command ] ” Displays a short help text for each command . If no command is specified after the help command, a list of all commands that the lpc program recognizes is displayed.

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 Statistics

Part 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 [-P  printer  ][-cmrs][-p  price  ][  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:

  • c ” Sorts the report by cost instead of machine/username.

  • m ” Groups charges by username with no regard to the hostname of the computer from which the job(s) were submitted.

  • r ” Reverses the sort order for the report.

  • s ” Summarizes the accounting data and writes it to a summary file. The summary file is usually in the form of printer .acct_sum .

  • p price ” Allows you to specify the cost per unit (foot or page) for print jobs. The default is two cents per unit.

  • username ” If you supply usernames at the end of the command, only statistics for print jobs for those users are included in the report.

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 System

Another 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 lpstat

The 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:

  • c ” A copy of the file to be made before it is printed. The default action is to create a link to the file. If you use the -c parameter, you should not remove (delete) the file before it is printed. Any changes you make to the file after submitting the print request will not be reflected in the output if you use this parameter to create a copy of the file.

  • d dest ” Specifies the destination printer or class for the print job.

  • f form-name ” Specifies a form to be mounted on the printer to process the print request. If the printer does not support the form, the request is rejected. Note that if you use the -d any parameter with this one, the print request can be sent to any printer that supports the form.

  • H special-handling ” Puts the print request on hold or resumes requests that are holding. If you are an LP administrator, this command causes the request to be the next one to print. The terms you use for special-handling are hold , resume , and immediate , respectively.

  • m ” Send mail after the print job has finished.

  • n number ” The number of copies to print.

  • o option ” Specifies printer-dependent options. You can specify more than one option by using the -o parameter more than once. You also can include multiple options by enclosing them in quotes ”for example, -o " option1 option2 ..." .

    Terms you can use for the option are listed here:

    • nobanner ” Do not print banner page.

    • nofilebreak ” Do not insert a form-feed character between files when multiple files are printed.

    • length= scaled-decimal-number ” Specifies the page length. You can specify lines, inches, or centimeters. Length=66 specifies 66 lines per page, and length=11I specifies 11 inches per page, for example.

    • width= scaled-decimal-number ” Similar to the length option. Use this format to specify page width in columns, inches, or centimeters.

    • lpi =scaled-decimal-number ” Like length and width . Use this to specify line pitch (lines per inch).

    • cpi= scaled-decimal-number ” Like length and width . Use this to specify characters per inch. You also can use the terms pica (10 characters per inch), elite (12 characters per inch), or compressed (to allow the printer to fit as many characters on a line as it can).

    • stty=' stty-option-list ' ” Specifies options for the stty command. Enclose the list with single quotes if it contains blank characters.

  • P page-list ” If the filter can handle it, this causes only the pages specified by page-list to be printed. You can specify single pages or a range of pages.

  • p ” Enable notification on completion of the print request.

  • q priority-level ” Priority levels range from 0 (highest) to 39 ( lowest ). This parameter changes the print priority of a print request. Giving a request a lower priority causes it to print before requests with a higher priority.

  • s ” Suppress messages from lp.

  • S character-set or S print-wheel ” Used to select a character set or print wheel to be used on the printer for the request. If the character set or print wheel is not available, the request is rejected.

  • t title ” Prints title on the banner page. Use quotes around the text if it contains blank spaces.

  • T content-type ” Causes the request to be printed on a printer that supports content-type if available, or to use a filter to convert the content to the appropriate type. If you specify -r with this option, a filter will not be used. The request is rejected if no printer for this type is available and/or a filter cannot be used.

  • w ” Sends a message to the user's terminal after the print request completes. If the user is not currently logged in, a mail message is sent.

  • y mode-list ” Use mode-list options to print. The allowed values for mode-list are locally defined and the job is rejected if there is no filter to handle the request.

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:

  • a [ list ] ” Shows whether print destinations (printers or printer classes) are accepting print requests.

  • c [ list ] ” Displays the names of all classes and members of the class. You can identify specific classes using list .

  • d ” Displays the system's default print destination.

  • o [ list ] ” Displays the status of output requests. The list value can specify either printers, class names, or request-ids.

  • p [ list ] ” Displays the status of printers. Use list to specify printer names.

  • r ” Displays the status of the print scheduler daemon (lpsched).

  • s ” Displays summary information about the printing system.

  • t ” Displays all the available status information about the printing system.

  • u [ login-ID-list ] ” Displays the status of print requests for the users listed in login-ID-list .

  • v [ list ] ” Displays pathnames of the output device files for printers indicated by list . For remote printers, this displays the name of the remote system.

Administering the System: lpadmin , lpsched , and lpshut

The 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:

  • A alert-type [-W minutes ] ” Sets up an alert action that is invoked when a printer fault occurs. The alert-type can be mail (sends an email) or write (puts a message on an administrator's terminal). You also can use quiet to suppress alerts, showfault to execute a fault-handling procedure, or none to remove alerts. You also can specify a shell command to be executed.

  • c class ” Specifies a class to which the printer will belong. If class does not exist, it will be created. The -r parameter can be used to remove a printer from a specific class.

  • D comment ” Sets the text ( comment ) that is displayed when the user requests a full description of the printer.

  • e printername ” Copies the interface program used by an existing printer ( printername ) for use with the printer you are creating. You quickly can clone entries when adding a printer of a type you already have, or when you are setting up a network that has many printers of the same type at the same time.

  • i interface ” Specifies the interface program for the printer. See -e earlier in this list to copy an interface from an existing printer.

  • m model ” Selects the model interface program that comes with the lp print service. You cannot use -e or -i with this option.

  • s system-name [! printer-name ] ” Creates a remote printer. A remote printer is a printer on another system that you want your users to be able to use as if it were local. The system-name is the name of the computer on which the printer resides, and ! printer-name is the name the printer uses on the remote system. You can use a different printer name on your system than the name on the remote system.

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 daemon ”it 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:

  • lpshut ” This command stops all printers. Jobs that are currently printing are stopped, but they are reprinted in their entirety when the printers are again started, as are other print jobs waiting in the spooler directory. The user can continue to submit to a printer that has been stopped using this command. Use lpsched when you want to start printers again.

  • reject [-r reason ] printer ” This command stops a printer from printing, but users cannot continue to submit jobs to the printer for later printing. If you want the users to know what is happening with the printer, use the -r command and specify the text you want them to see. If the text contains blank characters (it's more than one word), enclose the text in quotes. To restart the printer, use the accept printer command.

  • disable[-c -W ] [ -r [ reason ] ] printer ” This command can be used to disable a printer temporarily while still allowing users to submit jobs to the spooling directory that will print when the queue is restored to service. The -c and -W options are exclusive. Use -c to cancel the job that is currently printing and -W to have the printer stop after the current job finishes. Both of these parameters are ignored if the printer is on a remote system. Again, use -r to specify text to be displayed to users (when they use the lpstat -p command to check the printer's status). Use the enable printer command to restart the printer.

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.



Upgrading and Repairing Networks
Upgrading and Repairing Networks (5th Edition)
ISBN: 078973530X
EAN: 2147483647
Year: 2003
Pages: 434

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net