Powered By GitBook
108.4. Manage printers and printing
Weight: 2
Description: Candidates should be able to manage print 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
Terms and Utilities:
    CUPS configuration files, tools and utilities
    /etc/cups/
    lpd legacy interface (lpr, lprm, lpq)
Although much of our communication today is electronic and paperless, we still have considerable need to print material from our computers.

cups

CUPS is the standards-based, open source printing system developed by Apple Inc. for macOS® and other UNIX®-like operating systems.It stands for Common UNIX Printing System. The CUPS system can act as a printer server for a local machine or a network of machines.
CUPS consists of:
    Print spooler/scheduler: Lines up printing jobs to be sent to the printer.
    Filter system: Converts data so that the attached printer can understand and format the data being printed.
    Backend system: Transports data from filters to printer.
At the heart of the CUPS printing system is the cupsd print server which runs as a daemon process.

cups web interface

There are different interfaces for cups like gui , web interfaces and even traditional command line interfaces. Here we show the CUPS web administration tool (http://localhost:631 or http://127.0.0.1:631) to search for or add printers.
If you are asked for a username and password when accessing the CUPS web interface (localhost:631), use your login name and password.
Obviously adding printer requires root access.(in ubuntu members of cups admin group are accepted too)
1
### cups tree of menus:
2
-Home
3
-Administration ---> For Adding printers, managing jobs,
4
and configuring the CUPS works as server.
5
-classes
6
-Help
7
-Jobs ---> to check the jobs the CUPS is handling
8
-Printers ---> shopw the orinters
Copied!
We need to know what driver to use for your printer. Not all printers are fully supported on Linux and some may not work at all, or only with limitations. Check the printer manufacturer’s website or take a look at OpenPrinting.org.

/etc/cups

The /etc/cups directory contains other configuration files related to CUPS (Fedora 30).
1
[[email protected] ~]# ls -l /etc/cups
2
total 100
3
-rw------- 1 root lp 128 Dec 9 15:01 classes.conf
4
-rw-r----- 1 root lp 128 Dec 9 14:47 classes.conf.O
5
-rw-r--r--. 1 root lp 0 Nov 9 2018 client.conf
6
-rw-r--r--. 1 root root 27075 Apr 25 2018 cups-browsed.conf
7
-rw-r-----. 1 root lp 6278 Nov 9 2018 cupsd.conf
8
-rw-r-----. 1 root lp 6278 Nov 9 2018 cupsd.conf.default
9
-rw-r-----. 1 root lp 3000 Dec 4 2018 cups-files.conf
10
-rw-r-----. 1 root lp 3000 Nov 9 2018 cups-files.conf.default
11
-rw-r--r--. 1 root lp 0 Nov 9 2018 lpoptions
12
drwxr-xr-x. 2 root lp 4096 Dec 9 14:56 ppd
13
-rw------- 1 root lp 646 Jan 1 14:55 printers.conf
14
-rw------- 1 root lp 596 Jan 1 14:30 printers.conf.O
15
-rw-r--r--. 1 root lp 142 Nov 9 2018 snmp.conf
16
-rw-r-----. 1 root lp 142 Nov 9 2018 snmp.conf.default
17
drwx------. 2 root lp 4096 Nov 9 2018 ssl
18
-rw-r----- 1 root lp 421 Feb 19 17:39 subscriptions.conf
19
-rw-r----- 1 root lp 421 Feb 19 16:41 subscriptions.conf.O
20
-rw-r--r--. 1 root root 91 Dec 8 2018 thnuclnt.convs
21
-rw-r--r--. 1 root root 75 Dec 8 2018 thnuclnt.types
Copied!
The CUPS configuration file is normally located in /etc/cups/cupsd.conf
1
MaxLogSize 0
2
#
3
# Configuration file for the CUPS scheduler. See "man cupsd.conf" for a
4
# complete description of this file.
5
#
6
7
# Log general information in error_log - change "warn" to "debug"
8
# for troubleshooting...
9
LogLevel warn
10
11
12
# Only listen for connections from the local machine.
13
Listen localhost:631
14
Listen /var/run/cups/cups.sock
15
16
# Show shared printers on the local network.
17
Browsing On
18
BrowseLocalProtocols dnssd
19
20
# Default authentication type, when authentication is required...
21
DefaultAuthType Basic
22
23
# Web interface setting...
24
WebInterface Yes
25
26
# Restrict access to the server...
27
<Location />
28
Order allow,deny
29
</Location>
30
31
# Restrict access to the admin pages...
32
<Location /admin>
33
Order allow,deny
34
</Location>
35
36
# Restrict access to configuration files...
37
<Location /admin/conf>
38
AuthType Default
39
Require user @SYSTEM
40
Order allow,deny
41
</Location>
42
43
# Restrict access to log files...
44
<Location /admin/log>
45
AuthType Default
46
Require user @SYSTEM
47
Order allow,deny
48
</Location>
49
50
# Set the default printer/job policies...
51
...
Copied!
note1:The default CUPS configuration limits administration to the local machine.
note2: Most of the settings are accessible from the web interface and it is not recommended to edit this file.
If any printer has been configured, the setting are stored in etc/cups/printers.conf
1
# Printer configuration file for CUPS v2.2.6
2
# Written by cupsd on 2020-01-01 14:55
3
# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING
4
<DefaultPrinter HP-LaserJet-p2055d>
5
UUID urn:uuid:b55fdcb1-be5e-30a4-6fc5-d6e237a3c41a
6
AuthInfoRequired username,password
7
Info HP LaserJet p2055d
8
MakeModel HP LaserJet p2055d pcl3, hpcups 3.18.6
9
DeviceURI smb://172.16.130.2/HP%20LaserJet%20P2050%20Series%20PCL6
10
State Stopped
11
StateMessage Rendering completed
12
StateTime 1577877637
13
ConfigTime 1575890776
14
Reason paused
15
Type 36892
16
Accepting Yes
17
Shared No
18
JobSheets none none
19
QuotaPeriod 0
20
PageLimit 0
21
KLimit 0
22
OpPolicy default
23
ErrorPolicy stop-printer
24
</DefaultPrinter>
25
Copied!
DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING!

lpd legacy interface

In UNIX and Linux systems, printing initially used the Berkeley Software Distribution (BSD) printing subsystem, consisting of a line printer daemon (lpd) running as a server, and client commands such as lpr to submit jobs for printing.
Nowadays many of these legacy tools still exist to keep backward compatibility.
command
usage
lpr
send file to printer
lpq
show print jobs
lprm
remove print jobs
lpc status
show printer status
lpq : q stands for queue and it is use full when we want to see printer jobs
    -P : show the jobs of specific printer
    -a : show jobs of all printers.
1
[[email protected] ~]# lpq -PHP-LaserJet-p2055d
2
HP-LaserJet-p2055d is not ready
3
Rank Owner Job File(s) Total Size
4
1st payam 15 Untitled Document 1 13312 bytes
5
2nd payam 16 MOP template.docx 16384 bytes
Copied!
There should be no space between -P and Printer's name! -Pprintername
lpr : The simplest way to print any file is to use the lpr command and provide the file name. Again use -P to specify printer:
1
[[email protected] ~]# lpr -PHP-LaserJet-p2055d minicom.log
3
HP-LaserJet-p2055d is not ready
4
Rank Owner Job File(s) Total Size
5
1st payam 15 Untitled Document 1 13312 bytes
6
2nd payam 16 MOP template.docx 16384 bytes
7
3rd root 17 minicom.log 2048 bytes
8
Copied!
lprm : lprm removes job(s) from the printer's queue. We need to define Job ID for this command, if no Job ID is specified the older job is removed.
2
HP-LaserJet-p2055d is not ready
3
Rank Owner Job File(s) Total Size
4
1st payam 15 Untitled Document 1 13312 bytes
5
2nd payam 16 MOP template.docx 16384 bytes
6
3rd root 17 minicom.log 2048 bytes
7
[[email protected] ~]# lprm 15
9
HP-LaserJet-p2055d is not ready
10
Rank Owner Job File(s) Total Size
11
1st payam 16 MOP template.docx 16384 bytes
12
2nd root 17 minicom.log 2048 bytes
13
15
HP-LaserJet-p2055d is not ready
16
Rank Owner Job File(s) Total Size
17
1st root 17 minicom.log 2048 bytes
Copied!
again -P can be used to specify the printer. Also we can use lprm -Pprintername - to remove all printer's jobs. And lprm - will remove all jobs from the default printer.
Each user can remove his/her own jobs, but root can do any thing!
lpc : we can use lpc status command in order to check the printer health and troubleshoot (become root for better results!).
1
[[email protected] ~]# lpc status
2
HP-LaserJet-p2055d:
3
printer is on device 'smb' speed -1
4
queuing is enabled
5
printing is disabled
6
1 entries
7
daemon present
Copied!
where
    queuing is enabled: it means that printer will accept new jobs, if it was disabled it won't accept any new job even if the printer was ok.
    printing is disabled: means that printer can not actually print on the paper. That happens if the printer is out of ink or paper or experiencing a paper jam.
In my case, my printer is out of paper. But there are some other cups command which might be helpful specially when a problem occurs:
command
describe
cupsaccept
tells the printer queue to accept new jobs
cupsreject
tells the printer to reject any new job
cupsenable
enables the actual/physical printing of the jobs
cupsdisable
disables the physical printing of the jobs
with all commands we can specify printer's name without -P switch !
1
[[email protected] ~]# lpc status
2
HP-LaserJet-p2055d:
3
printer is on device 'smb' speed -1
4
queuing is enabled
5
printing is disabled
6
1 entries
7
daemon present
Copied!
Adding some papers :
1
[[email protected] ~]# cupsenable HP-LaserJet-p2055d
2
3
[[email protected] ~]# lpc status
4
HP-LaserJet-p2055d:
5
printer is on device 'smb' speed -1
6
queuing is enabled
7
printing is enabled
8
1 entries
9
daemon present
Copied!
And if we want to disable a printer intentionally, we can mention the reason with -r switch:
1
[[email protected] ~]# cupsreject HP-LaserJet-p2055d -r "Adding more paper"
2
[[email protected] ~]# lpc status
3
HP-LaserJet-p2055d:
4
printer is on device 'smb' speed -1
5
queuing is disabled
6
printing is enabled
7
1 entries
8
daemon present
Copied!
that's all!
.
.
.
.
Last modified 1yr ago