Read LPI Linux Certification in a Nutshell Online
Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger
Tags: #Reference:Computers
lp
lp [ -E ] [ -Uusername
] [ -c ] [ -ddestination
[/instance
] ]
[ -hhostname
[:port
] ] [ -m ]
[ -nnum-copies
] [ -ooption
[=value
] ] [ -qpriority
] [ -s ] [ -ttitle
]
[ -Hhandling
] [ -Ppage-list
] [ -- ] [file(s)
]
lp
submits files for printing
or alters a pending job.
Prints from standard input.
destination
Prints files to the named printer.
name
=value
[name
=value
...]”Sets one or more job options.
Print a double-sided legal document to a printer called
“foo”:
$lp -d foo -o media=legal -o sides=two-sided-long-edge filename
Print an image across four pages:
$lp -d bar -o scaling=200 filename
Print a text file with 12 characters per inch, 8 lines per
inch, and a 1-inch left margin:
lp -d bar -o cpi=12 -o lpi=8 -o page-left=72 filename
cancel
cancel [ -E ] [ -Uusername
] [ -a ] [ -hhostname
[:port
] ] [ -uusername
] [id
]
[destination
] [destination-id
]
cancel
removes the specified
print jobs from the queue.
Cancels all jobs on the named destination, or all jobs
on all destinations if no destination is provided.
lpstat
lpstat [ -E ] [ -Uusername
] [ -hhostname
[:port
] ] [ -l ] [ -Wwhich-jobs
]
[ -a [destination(s)
] ] [ -c [class(es)
] ] [ -d ]
[ -o [destination(s)
] ]
[ -p [printer(s)
] ] [ -r ] [ -R ] [ -s ] [ -t ] [ -u [user(s)
] ]
[ -v [printer(s)
] ]
lpstat
displays status
information about the current classes, jobs, and printers. When
run with no arguments, it lists jobs queued by the current
user.
printer(s)
]Shows the accepting state of printer queues. If no
printers are specified, shows all printers.
Shows all status information. This option is very
useful for troubleshooting.
lpadmin
lpadmin [ -E ] [-Uusername
] [ -hserver
[:port
] ] -ddestination
lpadmin [ -E ] [-Uusername
] [ -hserver
[:port
] ] -pprinter option(s)
lpadmin [ -E ] [-Uusername
] [ -hserver
[:port
] ] -xdestination
lpadmin
configures printer and
class queues provided by CUPS. It can also be used to set the
server default printer or class.
Sets a standard System V interface script or PPD file
from the model directory.
device-uri
Sets the device URI attribute of the printer queue. Ifdevice-uri
is a filename, it is
automatically converted to the formfile:///
file
/
name
.
Use the
lpinfo
(8) command for a list of
supported device URIs and schemes.
Enables the printer and accepts jobs; this is the same
as running the
accept
and
cupsenable
programs for a specific
printer.
lpq
lpq [options
] [users
] [job#s
]
Query a print queue. If numericjob#s
are included, only those jobs are
listed. Ifusers
are listed, only jobs
submitted by those users are listed.
Long output format. This option results in a multiline
display for each print job.
name
This specifies the print queuename
. In the absence of
-P
, the default printer is
queried.
Examine active jobs:
$lpq
lp is ready and printing
Rank Owner Job Files Total Size
active root 193 filter 9443 bytes
1st root 194 resume.txt 11024 bytes
2nd root 196 (standard input) 18998 bytes
Here,
filter
is currently being
printed.
resume.txt
is up next, followed by
the 18,998 bytes of data piped into
lpr
’s
standard input.
Examine those same jobs using the long format:
$lpq -l
lp is ready and printing
root: active [job 193AsJRzIt]
filter 9443 bytes
root: 1st [job 194AMj9lo9]
resume.txt 11024 bytes
root: 2nd [job 196A6rUGu5]
(standard input) 18998 bytes
Examine queuelp
, which
turns out to be empty:
$lpq -Plp
no entries
Examine jobs owned by
bsmith
:
$lpq bsmith
Rank Owner Job Files Total Size
7th bsmith 202 .bash_history 1263 bytes
9th bsmith 204 .bash_profile 5676 bytes
Using the job numbers reported by
lpq
,
any user may remove her own print jobs from the queue, or the
superuser may remove any job.
lprm
lprm [-Pname
] [users
] [job#s
]
lprm -ly
Remove jobs from a print queue. In the first form,
remove jobs from queuename
or from the
default queue if
-P
is omitted. Ifusers
orjobs
are specified, only those jobs
will be removed. In the second form, all of a normal user’s jobs
will be omitted; for the superuser, the queue will be
emptied.
As a normal user, remove all of your print jobs:
$lprm -
As the superuser, remove all jobs from queue
ps
:
#lprm -Pps -
You may occasionally be surprised to see ano entries
response fromlpq
, despite observing that the printer
is dutifully printing a document. In such cases, the spool has
probably been emptied into the printer’s buffer memory, and the
result is that the job is no longer under the control of the
printing system. To kill such jobs, you need to use the printer’s
controls to stop and delete the job from memory.
lpr
lpr [options
] [files
]
Sendfiles
or standard
input to a print queue. A copy of the input source is placed in
the spool directory under
/var/spool/lpr
until the print job is complete.
number
Sendnumber
copies of the
print job to the printer.
Instead of copying a file to the print spooling area,
make a symbolic link to the file, thereby eliminating
transfer time and storage requirements in
/var/spool/lpr
. This can relieve load
on the daemon’s system for very large files.
name
Specify the print queuename
. In the absence of
-P
, the default printer is
queried.
Print the file
/etc/fstab
on the
default print queue:
#lpr /etc/fstab
Print a manpage by piping to
lpr
’s
standard input:
#man -t 5 printcap | lpr
Disable a print queue:
#lpc disable lp
Then, attempt to print three copies of a file to the
disabled queue as superuser:
#lpr -#3 /etc/fstab
This succeeds, despite the disabled printer queue. Now try
as a regular user:
$lpr -#3 ~/resume.txt
lpr: Printer queue is disabled
As expected, normal users can’t print to the disabled
queue.
On the Exam
You must be familiar with
lp
and its use with both
files and standard input. Also remember that
lp
doesn’t send data to the printer but to
the printer daemon (
cupsd
on Linux), which
handles sending it to the printer backend and then to the
printer.
Logfiles are the first, and sometimes the best, guide to
solving problems with printing. Many people still make the basic mistake
of forgetting to check logfiles. These files are rotated, so that you can
find recent events in the main file and older events in gzipped backup
files. If you need even more detail, change theLogLevel
line in
/etc/cups/cupsd.conf
to the valuedebug
. It will dump loads of extra
information into the logfiles for subsequent print operations.
You should also know about the
cups-config
command, which has some options that show you information about the
current state of the system.
Recent errors and related information can be found in
/var/log/cups/error_log
. This file
lists messages from the scheduler, which includes both errors and
warnings. You can view detailed and real-time information about data
transferring, filtering, etc. Sample messages generated by one typical
job are:
I [16/Nov/2009:11:19:07 +0100] [Job 102] Adding start banner page "none".
I [16/Nov/2009:11:19:07 +0100] [Job 102] Adding end banner page "none".
I [16/Nov/2009:11:19:07 +0100] [Job 102] File of type application/postscript
queued by "brunop".
I [16/Nov/2009:11:19:07 +0100] [Job 102] Queued on "PDF" by "brunop".
I [16/Nov/2009:11:19:07 +0100] [Job 102] Started filter
/usr/libexec/cups/filter/pstops (PID 18223)
I [16/Nov/2009:11:19:07 +0100] [Job 102] Started backend
/usr/libexec/cups/backend/cups-pdf (PID 18224)
I [16/Nov/2009:11:19:07 +0100] [Job 102] Completed successfully.
I [16/Nov/2009:11:20:17 +0100] [Job ???] Request file type is
application/postscript.
I [16/Nov/2009:11:20:17 +0100] [Job 103] Adding start banner page "none".
I [16/Nov/2009:11:20:17 +0100] [Job 103] Adding end banner page "none".
I [16/Nov/2009:11:20:17 +0100] [Job 103] File of type application/postscript
queued by "brunop".
I [16/Nov/2009:11:20:17 +0100] [Job 103] Queued on "PDF" by "brunop".
I [16/Nov/2009:11:20:17 +0100] [Job 103] Started filter
/usr/libexec/cups/filter/pstops (PID 18340)
I [16/Nov/2009:11:20:17 +0100] [Job 103] Started backend
/usr/libexec/cups/backend/cups-pdf (PID 18341)
I [16/Nov/2009:11:20:17 +0100] [Job 103] Completed successfully.
TheI
that starts each line
stands for “information.” In this case, no errors or warnings were
generated.
This logfile can be found in
/var/log/cups/page_log
. It keeps information
from each page sent to a printer. Each line contains the following
information (when
applicable
):
printer user job-id date-time page-number num-copies job-billing \
job-originating-host-name
jobname media sides
A sample excerpt follows:
Photosmart_C4500 brunop 86 [31/Oct/2009:12:48:36 +0100] 1 1 - localhost
Photosmart_C4500 brunop 86 [31/Oct/2009:12:48:52 +0100] 2 1 - localhost
adamp23 brunop 87 [02/Nov/2009:13:40:33 +0100] 1 1 - localhost
adamp23 brunop 87 [02/Nov/2009:13:40:33 +0100] 2 1 - localhost
adamp23 brunop 88 [09/Nov/2009:09:31:11 +0100] 1 1 – localhost
PDF root 100 [16/Nov/2009:11:11:52 +0100] 1 1 - localhost
PDF brunop 101 [16/Nov/2009:11:16:38 +0100] 1 1 - localhost
This file can be found in
/var/log/cups/access_log
. It lists each HTTP
resource accessed by a web browser or client. Each line is in an
extended version of the so-called “Common Log Format” used by many web
servers and web reporting tools. A sample follows (lines broken to fit
the page of this book):
localhost - - [16/Nov/2009:17:28:29 +0100] "POST / HTTP/1.1" 200 138 \
CUPS-Get-Default successful-ok
localhost - - [16/Nov/2009:17:28:29 +0100] "POST / HTTP/1.1" 200 552 \
CUPS-Get-Printers successful-ok
localhost - root [16/Nov/2009:17:28:29 +0100] "GET /printers HTTP/1.1" \
200 11258 - -
localhost - root [16/Nov/2009:17:28:29 +0100] "GET \
/images/button-search.gif HTTP/1.1" 200 332 - -
localhost - root [16/Nov/2009:17:28:29 +0100] "GET \
/images/button-clear.gif HTTP/1.1" 200 279 - -
The
cups-config
utility has several
parameters that can be handy while troubleshooting. The options are
described in
Table 18-2
.
Table 18-2. Options to cups-config
Option | Description |
---|---|
--cflags | Displays the necessary compiler |
--datadir | Displays the default CUPS data |
--help | Displays the program usage |
--ldflags | Displays the necessary linker |
--libs | Displays the necessary libraries to |
--serverbin | Displays the default CUPS binary |
--serverroot | Displays the default CUPS |
On the Exam
Be familiar with the CUPS logfiles, and how to interpret them to
troubleshoot printing issues.