Keeping your CUPS from running over

—by David O’Donnell, atropos@afp548.com

7 November 2002

CUPS is pretty cool. As the backend to printing services on Mac OS X Server, it controls and administers local and shared printers. It also provides print services to command line users. If you haven’t already tried it, give it a whirl by launching Terminal and printing a text file (something short and sweet). To print the file “foobar,” issue the command

lpr foobar

at the command prompt. Depending on the speed of your printer or network (and whether you actually have any printers defined!) you should shortly see its output on your default printer. You can use the -# option (replacing the octothorpe with a number, such as “-10") to generate a number of copies. If you have multiple printers available, use the -P printer-name option to spool a job to a specific printer.

To see which printers CUPS thinks are attached to your computer, you can use the command

lpstat -a

which will also conveniently tell you the printers' ability to accept jobs, and the time when that state changed last. (You can also see the list of printers by pointing your browser at http://127.0.0.1:631/printers)

Interestingly enough, trying to print to an inkjet printer using the command line tool caused the printer to hold jobs. It wouldn’t print anything until the command-line printed job was deleted using the Print Center and the printer placed back online. CUPS also doesn’t seem to properly identify the default printer via its Web interface, but it does report properly if you use the lpstat -d command.

If you have sent a number of jobs to your printer, you can use the lpq command to see the queued jobs; use the -P printer-name option to specify a printer other than the default.

To delete one or more jobs from a print queue, use the command

cancel -d printer-name job-id

to cancel a specific job, or replace job-id with -a to cancel all queued jobs (for which you have administrative rights).

You can configure many of CUPS' options from the Web interface, but you may find it simpler to use the command line tool lpadmin. You will need to be super-user to use the command successfully. The man page for lpadmin covers the basics, and CUPS' documentation (available through the Web interface at http://127.0.0.1:631/sam.html) goes into greater detail. One of the more interesting (and useful) things you can do with lpadmin is control which users can actually print to any given printer.

To do this, you must know the CUPS name of the printer you wish to affect, and the first short name for all users you wish to control. You can allow or deny access to a printer using the following command format:

lpadmin -p printer-name -u {allow|deny}:{all|user-list}

Options separated by vertical bars and inside braces are exclusive; that is, you can either allow or deny access, either to all users or a user-list of users. The user-list consists of short names of users, separated by commas, without spaces. For example, if you have a printer called “LaserJet_6MP” and wish to allow all users to print to it, you would issue the command

lpadmin -p LaserJet_6MP -u allow:all

Conversely, to prevent users sam, alice, and phil from printing to that printer, you would use the command

lpadmin -p LaserJet_6MP -u deny:sam,alice,phil

lpadmin’s control list is exclusive and limited; you cannot supply a list of users to allow and a list of users to deny. The most recent command takes precedence and replaces all prior commands. If you deny specific users, lpadmin will still permit printing by all others.

Another useful thing lpadmin can do is apply a quota to a printer. For example, if you have a series of printers and one of them is a 1200-dpi color laser printer, you may want to restrict its use to a certain number of pages per day. To do this, you would use the command

lpadmin -p printer-name -o job-quota-period=86400 -o job-page-limit=pages

The '86400' above specifies one day, in seconds.