Controlling Printers


Printers and their associated queues are controlled with the lpc command. This command is used by the system administrator for printer administration. Some limited functionality is available to normal users, such as displaying the status of queues and restarting the printer daemon if it has died. Among other things, lpc can be used to enable and disable printers, enable and disable printer queues, change the order of jobs in the queue so that files at the bottom of the queue can be printed first, and check the status of queues.

If no command-line arguments are given to lpc, it will start in interactive mode with a prompt. You can also supply command-line arguments when starting lpc. If you do this, lpc will start, run the arguments specified on the command line, and then exit. You will start by looking at the interactive mode of lpc.

Using lpc in Interactive Mode

If lpc is started with no arguments, it will run in interactive mode. The interactive mode offers a prompt like this:

lpc>


You can type ? or help and press Enter to get a list of the available commands. Typing help followed by the name of one of the commands will give you a short, one-line description of what the command does.

When you type commands, they can be abbreviated to the shortest form that is not ambiguous. For example, the status command can be abbreviated as stat. However, it could not be abbreviated as sta because there is also a start command, and lpc would not know which one you wanted.

If you do not provide enough of the command for lpc to know which one you mean, it will respond with ?Ambiguous command. If the command you specify does not exist, it will respond with ?Invalid command.

Checking Queue Status

To check the status of a queue, use the status command (which, as mentioned previously, can be abbreviated stat). You also need to specify an argument, which can be either all to display the status of all daemons and queues, or the name of a printer to show the status for only that printer. Here's an example:

lpc> status lp lp:         queuing is enabled         printing is enabled         2 entries in spool area         waiting for lp to become ready (offline?)


This gives you the status for the system default line printer. In this case, the queue is enabled, printing is enabled, and two entries are sitting in the queue waiting to be printed. However, nothing is printing because the printer is unavailable, and lpc suggests that it may be offline.

The status command can be run by both normal users and system administrators.

Disabling, Printing, and Stopping the Daemon

The abort and stop commands can be used by the system administrator to disable printing and also terminate the daemon that handles spooling for the printer. Both commands require an argumenteither all, which will disable printing on all the queues and terminate the daemons, or the name of a printer, which will cause the command to affect only the named printer.

The abort command terminates printing immediately and stops the daemon that handles spooling for that printer. Here's an example:

lpc> abort lp lp:         printing disabled         daemon (pid 597) killed


And here is the output of the status command after the preceding command:

lpc> status all lp:         queuing is enabled         printing is disabled         2 entries in spool area         printer idle


There are two important points to note about this output:

  • Two entries are still listed in the spool area. The abort command simply kills the daemon and disables the printer. It does not remove any jobs from the spool area. When the daemon is restarted and the printer is enabled again, the jobs that are in the spool area will resume printing.

  • Queuing is enabled. This means you (and others) can still send jobs to the printer. They will be placed in the queue to wait until the daemon is restarted and the printer is enabled. At that point, any jobs submitted while the printer was disabled will be printed, along with any jobs that were already in the queue.

The stop command works similarly to the abort command, except it will wait until the current job has finished printing before it disables the printer and stops the spool daemon. As with abort, stop does not flush existing jobs from the queue, and the queue will still accept jobs that users submit and hold them for printing whenever the printer becomes available.

Tip

If you will be taking a printer down for an extended period of time (for maintenance, for example), consider aliasing that printer's name and its aliases to another printer in /etc/printcap. If it's the system default printer entry you're redirecting, make sure you also alias lp to a different printer. This will redirect any print jobs sent to that printer to a different printer without requiring users to make any changes to their configuration. Preferably, of course, you will want to alias the downed printer to a printer that is of a similar type and is located in the building fairly close to where the downed printer is located. In addition, you will probably want to send a systemwide email to the affected users, letting them know where they can pick up their print jobs for the time being until the printer they normally use is available again.


Disabling Print Queuing

Neither abort nor stop disables the queue. If you are taking a printer down for maintenance, for example, and you simply issue an abort command to kill the daemon and disable the printer, the queue will still be available. Users will be able to continue to send jobs to this printer as if nothing is wrong, and the queue will happily accept the jobs and store them to print whenever the printer becomes available. To keep your users' expectations realistic, you will probably want to disable the queue if the printer will be down for an extended period of time. There are two ways that this can be done.

The first method is with the disable command. It requires an argument that can either be all to disable all queues on the system or the name of a particular printer to disable the queue for only that printer. Here's an example:

lpc> disable lp lp:         queuing disabled lpc> status all lp:         queuing is disabled         printing is enabled         3 entries in spool area         waiting for lp to become ready (offline?)


In this case, the queue is disabled, but printing is still enabled. This means that the printer will continue to print all jobs currently in the queue (if it can), but the queue will not accept any new jobs.

If you try to send a job to a printer with a downed queue that is not accepting jobs, you will get an error similar to the following:

# lpr myfile.txt lpr: Printer queue is disabled


The other way that a queue can be disabled is by using the down command. Like the disable command, it requires at least one argument, which can either be all to affect all queues on the system or the name of a printer to affect only one printer.

The down command actually sends a stop command, which disables the printer and the spool daemon after the current job has finished printing, and then sends a disable command to bring down the queue. The down command can also take an optional message as an argument. The message will be written to the status file in the printer's spool directory. This will then be displayed in the output of lpq to let users know why the queue is not accepting their requests. Here's an example:

lpc> down lp Printer is down for maintenance. lp:         printer and queuing disabled


If lpq is then run, it will respond with the following:

# lpq Warning: lp is down: Printer is down for maintenance. Warning: lp queue is turned off Printer is down for maintenance. Rank   Owner      Job  Files                               Total Size


To enable a downed queue, simply type enable all to enable all queues. Alternatively, you can type the name of a printer to enable only the queue on that printer. Here's an example:

lpc> enable lp lp:         queuing enabled lpc> status lp lp:         queuing is enabled         printing is disabled         3 entries in spool area         Printer is down for maintenance.


Notice that although this brought the queue back up, it did not reenable the printer. Currently, the queue will accept jobs, but they will not be printed. If you used the down command to bring down the queue, use the up command to bring it back up. This will reenable the queue, restart the spooling daemon, and enable the printer. It will not, however, clear the status message. To clear the status message, you will need to run the restart command, as discussed in the next section.

Restarting a Spooling Daemon

If you need to restart a spooling daemon, you can use the restart command. If there is no daemon currently running, this command will start one. If there is currently a daemon running, this command will kill it and restart it (see the following caution, however). This can be used to reset a daemon that seems to have hung, for example.

The restart command requires an argument that can be either all to restart all print daemons on the system or the name of a printer to restart only the daemon for that printer. Here's an example:

lpc> restart lp lp:         daemon (pid 2102) killed lp:         daemon started


Caution

Occasionally, the restart command kills a running daemon but doesn't restart it again, even though it claims it did. Because of this, it is a good idea to check the output of lpq for the printer in question. If lpq says in the status line Warning: no daemon present, it means that lpc stopped the daemon when the restart command was issued but then failed to restart it again. If this is the case, simply run the restart command again from lpc, and this will take care of the problem.


Cleaning the Queue Directory

The clean command in lpc causes it to clean out the queue directory. It will remove any control files and related print job fragments that cannot be printed. Like most commands in lpc, the clean command requires an argument of either all or the name of the printer spool directory that you want to clean.

Changing the Priority of Print Jobs

You can use the topq command to change the order of print jobs in the queue (that is, to move jobs at the bottom or middle of the queue up to the top so they print faster).

Only a system administrator can change the order of the print jobs. The basic syntax of topq is:

topq printername jobnum(s) ...


where printername is, of course, the name of the printer, and jobnum(s) is a list of job numbers you want to move to the top of the queue. You can specify multiple job numbers with the command, and it will print them in the order listed. The first job listed will be moved to the top of the queue, the second will be second in the queue, and so on. For example, suppose the queue currently looks like this:

Rank   Owner    Job  Files                    Total Size 1st    btman    8    myfile.txt               151625 bytes 2nd    btman    9    cardlist.txt             38311 bytes 3rd    btman    10   lions.txt                1113 bytes 4th    btman    12   schedule.txt             6599 bytes


To reverse the order of these jobs in lpc, type topq lp 12 10 9 8. The results are shown here:

lpc> topq lp 12 10 9 8 lp:         moved cfA008simba.example.com         moved cfA009simba.example.com         moved cfA010simba.example.com         moved cfA012simba.example.com


If you look at the queue again, here's what you see:

Rank   Owner   Job  Files                         Total Size 1st    btman   12   schedule.txt                  6599 bytes 2nd    btman   10   lions.txt                     1113 bytes 3rd    btman   9    cardlist.txt                  38311 bytes 4th    btman   8    myfile.txt                    151625 bytes


The topq command can also take a username instead of a list of jobs. When topq is used this way, it will move all the jobs from the named user to the top of the queue.

Note that topq does not preempt a job that is currently running. It moves the jobs listed to the top of the queue so that they are next in line, but whatever job was printing before topq was used will finish printing before the job moved to the top of the queue starts. If you want a particular job to print right away, you will first have to use lprm to remove the job that is currently printing.

Quitting lpc

To quit the lpc program, simply type either quit or exit at the lpc> prompt. This will put you back at the command line.

Using lpc in Noninteractive Mode

lpc can also be run in noninteractive mode, taking a command line which it will execute without presenting a prompt. This mode is useful for scripted applications, such as shell scripts you might write that perform printer maintenance functions. In this case, simply supply the command you want to perform, along with any parameters, after lpc on the command line.

When lpc is run in noninteractive mode, it expects the first argument to be the command and anything that follows to be arguments to the command. Here's an example:

# lpc restart lp lp:         daemon (pid 2280) killed lp:         daemon started


All the same commands available in interactive mode are also available in noninteractive mode.

Controlling Who Can Use lpc

Sometimes you might want to give other people the ability to control printers with lpc but not give them full root privileges on the system. The "operator" group allows you to do this.

Any user who is a member of the group "operator" can make full use of lpc without having full root access to the system. This will allow that user to change the priority of print jobs, start and stop print daemons, and bring queues up and down.

Refer to Chapter 13, "Users, Groups, and Permissions," for more information on groups and how to add users to a group.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

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