8.11 Printing from UNIX

Two commands used at the FreeBSD command prompt are intended as general-purpose print commands: lp and lpr.

8.11.1 lp

The lp command is simply a front end command that calls the lpr command with appropriate options. It's main use is to allow the running of precompiled binary programs and scripts that assume that the lp command is the official printing command.

8.11.2 lpr

The lpr command is the main command that is used to print files from the command prompts under the FreeBSD operating system. It is frequently spawned off as a child program, or used in pipes. For example, when the Netscape web browser's Print button is clicked, Netscape may create the PostScript output, but the output goes through the lpr command.

The lpr command, like many UNIX command-line printing programs, assumes that the default print queue name is lp. When the FreeBSD machine is set up, the administrator usually sets the lp queue to print through a filter that allows raw UNIX text sent to it to print properly. For example, if an HP LaserJet printer that doesn't have PostScript is connected to the server, the lp queue specifies in the /etc/printcap file the CRLF filter listed earlier. On the other hand, if an Apple Laserwriter that doesn't support ASCII is connected to the server, the a2psfilter would be specified in the /etc/printcap for the lp queue.

When printing raw text files usually the -p option is specified to lpr. When printing preformatted files, such as PostScript files, the -P option is used, which selects whatever queue is used to handle these job types.

8.11.3 Managing the UNIX Print Queue

Once the print jobs coming in from clients are received on the FreeBSD system and placed in the print spool, they are metered out at a slower rate to the various printers. If traffic activity is light, and few print jobs get sent through, the administrator can probably ignore the print queue as long as it continues to work. However, a busy network printer running at an optimal rate of speed usually has a backlog of unprinted jobs in the queue waiting for print time. To keep all users happy and to provide for the occasional rush print job, the UNIX LPD/LPR printing system has several administration commands which are described here.

8.11.3.1 Viewing the queue

On busy printers, and to troubleshoot stopped printers, users sometimes need to view the print jobs in the queue. Administrators also need to view the queue to see what jobs may need to be expedited. This can be done from the workstation that remotely submitted the job if the LPR client has the ability to do this. The Windows 3.1 LPR client discussed earlier has this capability. Unfortunately, many LPR clients don't, which means that the administrator must Telnet into the UNIX machine that the print queues are on and view them there.

The UNIX shell command used to view the queue is the lpq command. It is frequently run as lpq -a which shows jobs in all queues. The following is a sample output of the command:

# lpq -a
nec-raw:
Rank Owner Job Files                         Total Size
1st  tedm  19  C:/WLPRSPL/SPOOL/~LP00018.TMP 105221 bytes
2nd  tedm  20  C:/WLPRSPL/SPOOL/~LP00019.TMP 13488 bytes
3rd  root  3   hosts                         1220 bytes
4th  tedm  1   Printer Test Page             765 bytes
5th  tedm  2   Microsoft Word - CHAPTE10.DOC 15411 bytes

The first two jobs and the last two jobs came from remote clients, the third came from the command prompt.

8.11.3.2 Removing print jobs

Deleting unwanted print jobs that haven't yet printed from the queue can be done by the remote workstations that submitted the job if their LPR implementations have the necessary commands. The Windows 3.1 LPR client I detailed earlier has this capability. Many LPR clients don't, however, which means that the administrator must Telnet into the UNIX machine that the print queues are on and delete the jobs there.

The administrator can delete any print jobs from any queues by running the lprm command followed by the specified print queue and the job number. Below is a sample output of the command:

# lprm -P nec-raw 19
dfA019tedmitte dequeued
cfA019dostest dequeued
# lprm -P nec-raw 3
dfA003toybox.placo.com dequeued
cfA003toybox.placo.com dequeued

The lprm command is also used under UNIX to delete remote print jobs.

8.11.3.3 Advanced management

The administrator logged into the FreeBSD system as the root user can also perform several other operations that ordinary users cannot. These include turning the queues on and off, and moving print jobs within the print queues. The command used to do this is the lpc command.

lpc has two modes of operation. In the first mode, the command is run by itself, which puts the administrator into an lpc prompt. Some general help is available for the commands, such as the following sample output:

# lpc
lpc> help
Commands may be abbreviated.
Commands are:
abort enable disable help restart status topq ?
clean exit down quit start stop up
lpc> help disable
disable turn a spooling queue off
lpc> help status
status show status of daemon and queue
lpc> exit

In the second mode of operation the lpc command is just run by itself, followed by the command and the print queue name. Following is a sample output:

# lpc disable lp
lp:
queuing disabled

Under FreeBSD, there is no command that specifically allows the administrator to move jobs from one queue to another. This can be done, however, by changing into the raw queue directory then rerunning the lpr command. Following is a sample run showing three print jobs moved from a dysfunctional queue to a good one:

# lpq -a
lp:
Warning: lp is down: printing disabled
printing disabled
Rank Owner Job Files                      Total Size
1st  root  51  hosts                      1220 bytes
2nd  root  52  services                   60767 bytes
3rd  root  53  printcap                   2383 bytes
# cd /var/spool/output/lpd
# ls
.seq cfA053toybox.placo.com dfA053toybox.placo.com
cfA051toybox.placo.com dfA051toybox.placo.com lock
cfA052toybox.placo.com dfA052toybox.placo.com status
# lpr -P nec-raw dfA051toybox.placo.com
# lpr -P nec-raw dfA052toybox.placo.com
# lpr -P nec-raw dfA053toybox.placo.com
# lprm -P lp -
# lpq -a
nec-raw:
Warning: nec-raw is down: printing disabled
Warning: no daemon present
Rank Owner Job Files                      Total Size
1st  root  5   dfA051toybox.placo.com     1220 bytes
2nd  root  6   dfA052toybox.placo.com     60767 bytes
3rd  root  7   dfA053toybox.placo.com     2383 bytes

Note: Moving jobs from queue to queue is feasible only when all printers are similar, as when all printers support PostScript.

8.11.3.4 Remote Management

Just as the root user can manipulate remotely submitted jobs in the print queue, print jobs can be remotely managed by regular users with the LPR clients that created them. Unfortunately, some LPR clients, such as the ACITS LPR client for Win95, don't have enough programming to be able to do this. Others, like the Win31 client, can manipulate the print jobs remotely.

FreeBSD offers some level of protection against inadvertent deletion of print jobs from remote hosts by restricting manipulation of a job to the same host that originated it. Even if the owner of the job matches a local user account on the server, for an ordinary user to delete remotely submitted print jobs, the request still must come from the remote host.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.