prq: A Print Queue Monitor and Manager
System administrators are occasionally asked to remove
print jobs already in the printing queue. To monitor
and manage printing
queues, BSD UNIX provides tools such as lpc, lpq,
and lprm. Each performs a specific task and produces
output. If used individually, they have some drawbacks.
is that each command must be retyped for each printing
the user wants to see. Another drawback is that users
various arguments or interactive commands. Although
there are reasons
why users should not be able to manage their own print
are hesitant to do so anyway and prefer to ask the system
to do it for them.
If combined in a script, these tools become faster and
easier to use.
This article presents such a script. The script speeds
and managing of the printing queues, and provides an
interactive interface to allow end users, less familiar
commands, the freedom to monitor and manage their own
It also serves as a convenient tool for system administrators,
that it lets you view and manage more than one print
queue at a time.
With several users vying for time on a limited number
for example, you might want to see which printer is
least used, so that you can get a print job out as quickly
Or perhaps you don't want the least-used queue, but
the queue holding
the fewest bytes. Byte size is relevant, because although
may have only two jobs waiting in the queue, if those
two jobs are
large documents, you may want to use the printer with
five small quick
jobs. To get such information, you would have to use
command in various forms for each printer on the network
prq script makes this process much simpler.
The prq Script
prq (Listing 1), short for printing queue, attempts
and simplify the process of monitoring and managing
the printing queue.
If you set permissions so that all end users of prq
the script, all of your users will have an easy, interactive
for working with their own print jobs. (You would, of
the names of printers listed in the sample code with
the names of
the printers on your own network.)
prq uses yes/no questions and menu selections to allow
user to interact with the printing queues, without having
arguments or type multiple commands. When invoked at
the prompt, prq
displays all printing queues on the network. It provides
lpq information for each printing queue, including the
rank, the user's name, the job's number, the file's
name, and the
After prq displays all printing queues, it asks whether
want to remove a particular print job. If you respond
with an "n"
or any other key, you will be returned to the shell
prompt. If you
respond with a "y," you will be given a menu
The menu is divided into two regions. The first region
gives the option
of removing a particular print job from a particular
you are that print job's owner. Each menu number represents
printer on the network. The number of options is dependent
number of printers on your own network. In the sample
are given two laser printers, one PaintJet, and a plotter
from. Whichever print device you choose, the screen
will be cleared
and you will be prompted for the job number you wish
to remove from
the queue. You may enter a "-" to remove all
print jobs belonging
to you. A notification will be displayed, ensuring that
were dequeued, and the menu will display once more.
The second menu region gives various unrelated options.
If the screen
has scrolled past the job you wanted to remove and you
job number, you may reproduce the list. If you are currently
you can enter a second level of menu options from which
you can rearrange
print jobs in a particular printing queue. Finally,
if you change
your mind, you have the option of exiting back to the
For exiting, the menu prompt will accept either the
number of the
exit selection on the menu or the lower case "x"
If you choose the "Rearrange print jobs" option,
will test the HOME environment variable to see if you
a superuser. If this variable is not set to "/",
the root directory, then you will see a message informing
you must be superuser to enter the menu level and the
will be redisplayed.
If you are currently a superuser, a second level of
menu options will
be displayed. Again, this set of options is divided
into two regions.
The first region is a set of printer devices for which
can be rearranged. Upon selecting a printing device,
you will be prompted
for job numbers to place at the top of the queue. You
can simply type
a user name and all jobs belonging to that user will
be placed at
the top of the queue. The system will notify you that
the task was
carried out and the menu selections will be redisplayed.
The second region holds the options to redisplay the
return to the previous level of menu options, or exit
to the shell
This script simplifies the system administrator's monitoring
of network printing queues. It also provides an easy-to-use,
interface for end users less familiar with the UNIX
them the freedom to manage their own print jobs. You
can add other
capabilities to the script easily.
The only drawback to prq is that, if the printers on
network change or one goes down, the script must be
modified in several
places to represent these changes or it is rendered
it isn't a particularly time-consuming task -- it's
file to maintain. The benefits should more than outweigh
About the Author
Robert Berry has been working with SunOS and DG/UX
He received his BS degree from the University of Maryland
and is working
on an MS degree from the University of West Florida.
He is currently
the Systems Administrator and Networking Manager at
& Software, Inc. His interests are in PC-to-UNIX
networking and network
programming. Robert Berry can be contacted at 242 Vickie
Fort Walton Beach, FL 32547. Fax (904) 862-8111.