108.4 Managing Printers and Printing edit

Candidates should be able to manage printer queues and user print jobs using CUPS and the LPD compatibility interface


Key Knowledge Areas

  • Basic CUPS configuration (for local and remote printers).
  • Manage user print queues.
  • Troubleshoot general printing problems.
  • Add and remove jobs from configured printer queues.

Introducing CUPS edit

CUPS (Common Unix Print System) is the standard print system on Linux. The cups server is cupsd; it listens on port 631 and accepts print jobs using IPP (the Internet Printing Protocol). IPP is layered over HTTP, in the sense that an IPP request is an HTTP request with a specific type of content.

 


Illustration 108.4-1: CUPS Printing System

The CUPS server handles printer queue management and also provides a web server (also on port 631) that supports a browser-based configuration interface allowing the addition and deletion of printers, printer queue management, and so on.

 

Figure 108.4-2: CUPS Web Interface: Home Page

CUPS filters

The internal work-flow within cups can be relatively complex:

 

Figure 108.4-3: Linux Printing Architecture

The front-end of CUPS is the actual server that handles the queuing of print jobs and provides the web-based configuration interface. Beyond that, at the heart of the work-flow are the filters, which provide format conversion from the initial input file (plain text, jpeg image, etc) to the language understood by the actual printer. These filters are based on Ghostscript (a GNU project). They consult PPD (Postscript Printer Description) files which specify the printer's capabilities. The filters are found in (for example) /usr/share/ghostscript.

Ghostscript can also be invoked from the command line with the name gs. This command takes postscript or PDF files as input and generates an output file for a specific printer type. It has a database of printer drivers it can handle (this list is reasonably up to date, for example many USB printers are supported) and converts the postscript directly into PCL for these known models. Run the command gs -h to see a list of supported devices:

# gs -h

GPL Ghostscript 8.71 (2010-02-10)

Copyright (C) 2010 Artifex Software, Inc. All rights reserved.

Usage: gs [switches] [file1.ps file2.ps ...]

Most frequently used switches: (you can use # in place of =)

-dNOPAUSE no pause after page | -q `quiet', fewer messages

-g<width>x<height> page size in pixels | -r<res> pixels/inch resolution

-sDEVICE=<devname> select device | -dBATCH exit after last file

-sOutputFile=<file> select output file: - for stdout, |command for pipe,

embed %d or %ld for page #

Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF

Default output device: x11alpha

Available devices:

alc1900 alc2000 alc4000 alc4100 alc8500 alc8600 alc9100 ap3250 appledmp

atx23 atx24 atx38 bbox bit bitcmyk bitrgb bitrgbtags bj10e bj10v bj10vh

bj200 bjc600 bjc800 bjc880j bjccmyk bjccolor bjcgray bjcmono bmp16 bmp16m

bmp256 bmp32b bmpgray bmpmono bmpsep1 bmpsep8 ccr cdeskjet cdj1600 cdj500

... many lines deleted ...


CUPS back-ends

CUPS supports a variety of back-ends. The term back-end refers to the technology or protocol used to connect to the printer. The table below gives some examples:

Table: CUPS Back-end Technologies
Back-end URI Syntax Example
Parallel port parallel:/dev/lpx parallel:/dev/lp0
USB usb://make/model?serial=number usb://hp/officejet123?serial=108442
ipp ipp://host/printers/queue ipp://neptune/printers/xerox1
LPD lpd://host/queue lpd://neptune/xerox1
socket socket://host:port socket://neptune:9100
CIFS smb://user:password@workgroup/host/share

CUPS printers can be added using the web-based interface. The figure below shows two of several screens in this sequence:

 

Figure 108.4-4: Adding a Printer - I

 

Figure 108.4-5: Adding a Printer - II

Printers can also be assigned to classes. This is mainly useful on heavy duty print servers that have several printers of the same type connected. Users send print jobs to a class; CUPS will print them on the first printer that becomes available.


Legacy commands for printing edit

CUPS replaces two earlier printing systems used in UNIX and Linux. One comes from System V Unix, and the other comes from BSD (Berkeley Software Distribution). These two systems were principally intended for printing of plain text files from the command line (and not, for example, printing of office documents with embedded images from a graphical application such as Open Office). The two systems, whilst conceptually similar, used different commands, different configuration files, and a different protocol to talk to the print server.

For backward compatibility, CUPS provides "work-alike" versions of many of these command-line tools. These include:

Command Description
lp, lpr submit files for printing
lpq print printer queue status
lprm remove a queued print job
accept Allow jobs to be sent to a print queue
reject Prevent jobs from being sent to a print queue
cupsenable Allow jobs to be sent from a queue to a printer
cupsdisable Stop jobs being sent from the queue to the printer
lpstat Show the status of the CUPS printer queues
lpadmin Configure cups printers and classes

When using CUPS, these command submit jobs to the CUPS server which performs its usual filtering and back-end processing.


lp and lpr

The lpr and lp utilities are used to submit jobs to a printer. Note that they use different command options. For example lpr uses the -P flag to specify the printer, lp uses the -d flag.


lpq

A user can monitor the status of print queues with lpq. In the example below, demo-1 is the name of the printer.

# lpr -Pdemo-1 anaconda-ks.cfg

# lpq -Pdemo-1

demo-1 is not ready

Rank Owner Job File(s) Total Size

1st root 4 install.log 39936 bytes

2nd root 5 anaconda-ks.cfg 1024 bytes


lprm

The lprm command is used to delete jobs from the print queue. In the example below we delete job 4 from the demo-1 print queue then redisplay the queue:

# lprm -Pdemo-1 4

# lpq -Pdemo-1

demo-1 is not ready

Rank Owner Job File(s) Total Size

1st root 5 anaconda-ks.cfg 1024 bytes


lpstat

lpstat displays status information about the current classes, jobs, and printers. When run with no arguments, lpstat will list jobs queued by the current user.

Example:

# lpstat -t

scheduler is running

no system default destination

device for demo-1: parallel:/dev/lp0

device for demo-2: ipp://printhost/ipp

demo-1 accepting requests since Sun 26 Sep 2010 12:38:10 PM BST

demo-2 accepting requests since Sun 26 Sep 2010 12:34:53 PM BST

printer demo-1 disabled since Sun 26 Sep 2010 12:38:10 PM BST -

Paused

printer demo-2 is idle. enabled since Sun 26 Sep 2010 12:34:53 PM BST

demo-1-5 root 1024 Sun 26 Sep 2010 12:39:30 PM BST


# lpstat

demo-1-5 root 1024 Sun 26 Sep 2010 12:39:30 PM BST


cupsenable and cupsdisable

These commands are used to enable and disable specified printer queues. cupsdisable stops jobs being taken from the queue and sent to the printer. It does not prevent new jobs being sent to the queue. cupsenable re-starts the servicing of the queue.


accept and reject

These commands are used to enable and disable the filling of specified printer queues. In the example below we use reject to disable the demo-1 queue, then attempt to print a file to it. We then re-enable the printer, and successfully send a job to the queue:

# reject demo-1

# lpr -Pdemo-1 scsconfig.log

lpr: Destination "demo-1" is not accepting jobs.


# accept demo-1

# lpr -Pdemo-1 scsconfig.log


lpadmin

The lpadmin command performs a variety of administrative operations on CUPS printers. For example it can be used to set the default printer. In the command sequence shown below there is initially do default destination set. After running lpadmin, we can print to the default printer by using lpr without specifying a printer name:

# lpr install.log

lpr: Error - no default destination available.


# lpadmin -d demo-1

# lpr install.log

lpadmin can also be used to delete CUPS printers. In the example below we first list the available queues, then use lpadmin to remove one of them, then list the queues again:

# lpstat -a

demo-1 accepting requests since Sun 26 Sep 2010 12:38:10 PM BST

demo-2 accepting requests since Sun 26 Sep 2010 12:34:53 PM BST


# lpadmin -x demo-1


# lpstat -a

demo-2 accepting requests since Sun 26 Sep 2010 12:34:53 PM BST



The following is a partial list of the used files, terms and utilities:

  • CUPS configuration files, tools and utilities
  • /etc/cups
  • lpd legacy interface (lpr, lprm, lpq)


Previous Chapter | Next Chapter