Cover V04, I01
Article
Listing 1
Sidebar 1
Sidebar 2
Sidebar 3

jan95.tar


prq: A Print Queue Monitor and Manager

Robert Berry

System administrators are occasionally asked to remove or rearrange 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 a specific output. If used individually, they have some drawbacks. One drawback is that each command must be retyped for each printing queue that the user wants to see. Another drawback is that users must remember various arguments or interactive commands. Although there are reasons why users should not be able to manage their own print jobs, many are hesitant to do so anyway and prefer to ask the system administrator 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 monitoring and managing of the printing queues, and provides an easy-to-use, interactive interface to allow end users, less familiar with UNIX commands, the freedom to monitor and manage their own print jobs.

It also serves as a convenient tool for system administrators, in 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 of printers, for example, you might want to see which printer is currently the least used, so that you can get a print job out as quickly as possible. Or perhaps you don't want the least-used queue, but the queue holding the fewest bytes. Byte size is relevant, because although a printer 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 the lpq command in various forms for each printer on the network -- the prq script makes this process much simpler.

The prq Script

prq (Listing 1), short for printing queue, attempts to speed and simplify the process of monitoring and managing the printing queue. If you set permissions so that all end users of prq can execute the script, all of your users will have an easy, interactive interface for working with their own print jobs. (You would, of course, replace 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 the user to interact with the printing queues, without having to remember arguments or type multiple commands. When invoked at the prompt, prq displays all printing queues on the network. It provides standard lpq information for each printing queue, including the job's rank, the user's name, the job's number, the file's name, and the file's size.

After prq displays all printing queues, it asks whether you 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 holding more options.

The menu is divided into two regions. The first region gives the option of removing a particular print job from a particular printer, provided you are that print job's owner. Each menu number represents a particular printer on the network. The number of options is dependent on the number of printers on your own network. In the sample script, you are given two laser printers, one PaintJet, and a plotter to choose 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 your jobs 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 forgot the job number, you may reproduce the list. If you are currently superuser, 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 shell prompt. For exiting, the menu prompt will accept either the number of the exit selection on the menu or the lower case "x" character.

If you choose the "Rearrange print jobs" option, the script will test the HOME environment variable to see if you are currently a superuser. If this variable is not set to "/", which represents the root directory, then you will see a message informing you that you must be superuser to enter the menu level and the previous menu 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 print jobs 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 printing queues, return to the previous level of menu options, or exit to the shell prompt.

Conclusion

This script simplifies the system administrator's monitoring and managing of network printing queues. It also provides an easy-to-use, interactive interface for end users less familiar with the UNIX environment, giving 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 your network change or one goes down, the script must be modified in several places to represent these changes or it is rendered useless. Modifying it isn't a particularly time-consuming task -- it's just another file to maintain. The benefits should more than outweigh this inconvenience.

About the Author

Robert Berry has been working with SunOS and DG/UX since 1991. 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 Spectrum Sciences & Software, Inc. His interests are in PC-to-UNIX networking and network programming. Robert Berry can be contacted at 242 Vickie Leigh Rd., Fort Walton Beach, FL 32547. Fax (904) 862-8111.