| Goals for this chapter: | rpm packages covered in this chapter:
|
|
|
|
In this chapter we will explain how to activate and manage the printer services in RedHat Linux.
RedHat includes the software LPR (originally written at BSD) for managing printing services. There are several UNIX versions that use the system command "lpr", originally introduced in UNIX BSD (Berkeley Software Distributions). UNIX SUN OS, NeXT, BSD, FreeBSD and others use this mode. SCO, UnixWare, AIX (IBM), Interactive, Ultrix (Digital), HP-UX (Hewlett-Packard), IRIX (Silicon Graphics) use the "lpstat" method from AT&T UNIX.
Caldera OpenLinux uses LPRng, different from lpr.
The lpr implementation lets you print through the program "lpr", line printer, that reads the file "/etc/printcap". All system printers are included in this file.
RedHat Linux always installs through the setup program (in the installation phase) the system printer label for your specific printer: "lp" that means line printer is the default printer (supported by the Print Plug-In with the use of the ghostscript interpreter)
The printer "lp" use a filter. Programs like Caldera WABI, Corel WordPerfect include their own "drivers" or printer filters. In these cases you must setup a new printer without the filter.
This is an example for the file "/etc/printcap":
[root@redhead /root]# more /etc/printcap
#
# Please don't edit this file directly unless you know what
you are doing!
# Be warned that the control-panel printtool requires a very
strict format!
# Look at the printcap(5) man page for more info.
#
# This file can be edited with the printtool in the control-panel.
##PRINTTOOL3## REMOTE deskjet 300x300 a4 {} DeskJet Default 1
lp:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:sh:\
:rm=192.168.1.60:\
:rp=ps:\
:if=/var/spool/lpd/lp/filter:
[root@redhead /root]#
Installing printers on RedHat Linux
RedHat Linux during the installation phase asks for the system printer:

The system printer can be modified at any time using the RedHat printtool program:

If you want to support two or more printers, you have to add the new printer with "printtool".
Now, we will show the standard procedure.
To add a new printer, choose "Add". After will
appears the following dialog mask.
![]() |
![]() |
| If you choose a "Local Printer" the program test your system the local device. | After this you can complete the entries for the new printer |
![]() |
![]() |
| ... and press the "Select" button |
You can choose the printer from the list and fix the "Resolution" and the "Paper Size", and press OK button. After this operation the new printer have been added.

To activate the new printer, you can run the following commands:
[root@heaven /root]# cd /etc/rc.d/init.d
[root@heaven init.d]# lpd reload
that are equivalent to running cd /etc/rc.d/init.d, lpd start; lpd stop. Anyway the new printers will be loaded at the next boot.
You can also run the button "Restart lpd" in the "lpd" menu, or reboot the machine.
RedHat Linux doesn't need any particular command for activating the printer. After the first printer installation, you can print. Of course it's necessary that the printer daemon (Print Server) is running on the machine and has been previously activated with "ntsysv".

Nothing else is necessary for printing on RedHat Linux.
For printing, just do the command :
[root@redhead /root]# lpr /etc/passwd
that will print the file "/etc/passwd" on the
default printer (local or network printer).
Sending a controlling printers jobs "lpr", "lpq" and "lprm"
All UNIX systems or Linux distributions have to set up a default printer. This is valid also for other operating systems.
In RedHat Linux the "default" printer is "lp". This was the reason why we don't have a parameter in the last "lpr" command.
Now we will see the printers on the "heaven" machine :
[root@heaven /root]# more /etc/printcap
# /etc/printcap
#
# Please don't edit this file directly
unless you know what you are doing!
# Be warned that the control-panel printtool
requires a very strict format!
# Look at the printcap(5) man page for
more info.
#
# This file can be edited with the printtool
in the control-panel.
#lp|ps:\
#
:sd=/var/spool/lpd/lp:\
#
:mx#0:\
#
:rm=world:\
#
:rp=ps:
ps|rcolorps:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:rm=world:\
:rp=ps:
rcolorlp:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:rm=world:\
:rp=lp:
rlaserps:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:rm=earth:\
:rp=ps:
rlaserlp:\
:sd=/var/spool/lpd/lp:\
:mx#0:\
:rm=earth:\
:rp=lp:
[root@heaven /root]#
The default printer on the "heaven" machine is a network printer "rm=world" (rm - means remote machine), "rp=ps" (rp - means remote printer). So the the "ps" printer for heaven is the "ps" printer for the machine "world".
In the same way the printer without a filter on the heaven machine is the corresponding printer on the machine "world".
The other printers listed in the file are also network printers attached to the machine "earth".
The lpr printer services are very transparent and clear.
To print, for example, on the printer "rlaserps" (the printer with a filter attached to the machine "earth"), we can run the command:
[root@heaven linux]# lpr -Prlaserps /etc/passwd
To check the status of a printer job, we can run the command :
[root@heaven linux]# lpq -Prlaserps
Printer: rlaserps is ps@earth
Printer: ps@earth
Queue: 1 printable job
Server: pid 14868 active
Unspooler: pid 14869 active
Status: printed all 906 bytes at
22:09:23
Rank Owner/ID
Class Job Files
Size Time
active root@heaven+296
A 296 /etc/passwd
906 22:09:23
[root@heaven linux]#
The command "lpq" without parameters displays the default printer queue. If the default printer is a network printer and the remote machine is down, the "lpq" command cannot tell us about the printer jobs:
[root@heaven /root]# lpq
Host 'world' - cannot open connection
to `ps@world' - No route to host
Once the remote machine is up, lpq informs us:
[root@heaven /root]# lpq
Printer: ps@world
Queue: no printable jobs in queue
Status: server finished at 19:08:19
[root@heaven /root]#
To find out all the printer jobs on all printers, we can run the command "lpq -a" :
[root@heaven /root]# lpq -a
Printer: ps@heaven (dest ps@world) 'rcolorps'
Queue: no printable jobs in queue
Printer: ps@world
Queue: no printable jobs in queue
Status: server finished at 19:08:19
Printer: rcolorlp@heaven (dest lp@world)
Queue: no printable jobs in queue
Printer: lp@world
Queue: no printable jobs in queue
Status: server finished at 18:02:49
Printer: rlaserps@heaven (dest ps@earth)
Queue: no printable jobs in queue
Printer: ps@earth
Queue: no printable jobs in queue
Status: server finished at 22:09:37
Printer: rlaserlp@heaven (dest lp@earth)
Queue: no printable jobs in queue
Printer: lp@earth
Queue: no printable jobs in queue
Status: server finished at 19:33:12
[root@heaven /root]#
The StarOffice printer jobs are listed as stdin (Standard Input) printer jobs :
[root@world /root]# lpq
Printer: ps@world
Queue: 1 printable job
Server: pid 866 active
Unspooler: pid 867 active
Status: printed all 133137 bytes
at 08:36:01
Rank Owner/ID
Class Job Files
Size Time
active root@world+865
A 865 (stdin)
133137 08:35:55
[root@world /root]#
To remove queued printers jobs, we can run the command "lprm" :
[root@heaven /root]# lpr /etc/printcap
[root@heaven /root]# lpr /etc/printcap
[root@heaven /root]# lpr /etc/printcap
[root@heaven /root]# lpq
Printer: ps@world
Queue: 3 printable jobs
Server: pid 1044 active
Unspooler: pid 1073 active
Status: printed all 769 bytes at
09:51:24
Rank Owner/ID
Class Job Files
Size Time
active root@heaven+975
A 975 /etc/printcap 769
09:51:23
2
root@heaven+976
A 976 /etc/printcap 769
09:51:24
3
root@heaven+977
A 977 /etc/printcap 769
09:51:25
[root@heaven /root]#
The number to "kill" is the "JOB" number (for example "975"). This is the command to do, to kill printer job number "975" :
[root@heaven /root]# lprm 975
Printer ps@world:
checking 'root@heaven+975'
checking perms 'root@heaven+975'
dequeued 'root@heaven+975'
killing subserver '1073'
checking 'root@heaven+976'
checking perms 'root@heaven+976'
not selecting 'root@heaven+976'
checking 'root@heaven+977'
checking perms 'root@heaven+977'
not selecting 'root@heaven+977'
[root@heaven /root]#
If we want to remove all the printer jobs (on all printers), we have to add the parameter "-a" :
[root@heaven /root]# lprm -a
Printer ps@world:
Printer lp@world:
Printer rlaserps@world:
Printer ps@earth:
Printer rlaserlp@world:
Printer lp@earth:
[root@heaven /root]#
The following commands allow us to manage printer jobs on OpenLinux: "lpr", "lpq", "lprm" and the daemon "lpd" that is executed at boot time.
In order to introduce the reader to all the printer
systems in all UNIX, we include a comparison table :
| AT&T | BSD | Command Description |
| lp | lpr | Send the file to the printer |
| lpstat | lpq | Check the printer queue |
| lpsched | lpd | The print daemon that starts at boot time for managing printer jobs |
| cancel | lprm | Remove printer jobs |
| lpstat,
lpstart lpshut lpmove |
lpc | Control, activate and remove system printers |
The AT&T column pertains to the first version. Each UNIX hardware vendor; IBM, DIGITAL, HP, Interactive and SCO modify AT&T UNIX to its special requirements.
The "lpr" command, for example, lets you send multiple copies of the same file, including a title on each page and other special features:
[root@heaven /root]# lpr -he
lpr: Illegal option 'e'
usage summary: %s [ -Pprinter[@host] ]
[-(K|#)copies] [-Cclass][-Jinfo]
[-Raccountname] [-m mailaddr]
[-Ttitle] [-i indent]
[-wnum ][ -Zoptions ] [ -Uuser
] [ -Fformat ] [ -bhkr ]
[-Ddebugopt ] [ filenames
... ]
-b,l
- binary or literal format
-Cclass - job class
-F format - job format
filter
-c,d,f,g,l,m,p,t,v are also
format specifications
-h
- no header or banner page
-i indent - indentation
-Jinfo - banner and
job information
-k
- non seKure filter operation, create temp file for input
-K copies, -# copies
- number of copies
-m mailaddr - mail error status
to mailaddr
-Pprinter[@host] - printer on host
(default environment variable PRINTER)
-r
- remove named files after spooling
-w width - width
to use
-Q
- put 'queuename' in control file
-Raccntname - accounting information
-T title - title
for 'pr' (-p) formatting
-U username - override user name
(restricted)
-V
- Verbose information during spooling
-Z filteroptions - options to pass
to filter
default job format -Ff
A filename of the form '-' will
read from stdin.
PRINTER environment variable is
default printer.
For example, to print two copies of the same file, you can do the following command (the banner is the default) :
[root@heaven /root]# lpr -#2 /etc/passwd
How to control print jobs with "lpc"
The LPRng package contains the program "lpc" for controlling printer jobs :
[root@redhead /root]#
lpc
lpc> ?
Commands may be abbreviated. Commands
are:
abort enable disable
help restart status topq ?
clean exit
down quit start stop
up
lpc>
With "lpc" it's possible to manage printer queues between several printers, move printer jobs from one printer to another, activate, stop or remove printer jobs.
The beginning user doesn't have to use the "lpc" program.
Printing files in various formats: gif, jpg, dvi and man
In RedHat Linux, as stated in the preceding chapters, you use the ghostscript ("gs") program produce printouts.
Is possible to display color Postscript or print Postscript files. With the new ghostscript, it's easy to print a Postscript file.
[root@heaven /root]# lpr chap11.ps
[root@heaven /root]#
Postscript files can be both printed and viewed not only with "gs" (ghostscript) but also with "gv" (ghostview).
[root@heaven /root]# gs chap11.ps
"ghostview" lets you print specific pages from a Postscript file; for example, pages 3 to 5. This is very useful in some situations.
"gv" is very similar to ghostview, but much more evolved.
If we try to print "gif" or "jpg" files, we find a small surprise:
[root@heaven /root]# lpr pullcable.jpg
lpr: Fatal error - cannot print 'pullcable.jpg':
unprintable file
[root@heaven /root]# lpr eps/ribbon.gif
lpr: Fatal error - cannot print 'eps/ribbon.gif':
unprintable file
[root@heaven /root]#
How can we print these files?
There are two methods. The first is to use a program like Communicator or "xv" and print on the desired printer.
The second method is to use "magic-filters" program, which you'll find at SUNsite. Once these filters are installed, you can use the lpr program to print almost any type of file format, including "gif" and "jpg."
Even if magic filter lets you print some of the formats that we will explain below, we will show an alternative solution that doesn't require the use of these filters.
To print a "man" page, just do this:
[root@heaven /root]# man cc | lpr -Prlaserps
On the Internet (as well as Linux standard documentation), you'll frequently find files in the DVI (Device Independent) format. Examples of files in "dvi" are on the CD in the "FTContribs/Files/TeX" directory.
These files were generated by the "tex" programs, which converts TeX files to DVI (for more information about the TeX format, see Chapter 17. Text Processing on Linux.)
OpenLinux includes several programs for converting these files.
To find out the most important, just enter "dvi" (and then press the ESC key twice, or TAB)
[root@heaven /root]# dvi
dvi2fax dviconcat
dvihp dvilj2p dvilj4l
dvired dvitodvi dvitype
dvibook dvicopy
dvilj dvilj4 dvips
dviselect dvitomp
[root@heaven /root]# dvi
The most frequently used utility is certanly "dvips", seeing as OpenLinux and Linux both can easily print these files. To generate a postscript file, you just add a parameter to the command, like this:
[root@heaven TeX]# dvips -o story.ps story
This is dvipsk 5.58f Copyright 1986, 1994
Radical Eye Software
' TeX output 1998.11.19:1900' - story.ps
<tex.pro. [1]
[root@heaven TeX]#
The efault is to send the output directly to the default printer! (This is not always convenient.)
[root@heaven TeX]# dvips story
This is dvipsk 5.58f Copyright 1986, 1994
Radical Eye Software
' TeX output 1998.11.19:1900' - |lpr
<tex.pro. [1]
You can also transform the file to PCL (the language built into HP LaserJet printers).
[root@heaven TeX]# dvilj story
[1]
All done, used font_storage of HP LaserJet:
26240 Bytes
Dynamically allocated storage: 27985 Bytes
52 characters downloaded as soft fonts
[root@heaven TeX]# ll *.lj
-rw-r--r-- 1 root
root 6231 Nov 19 19:11
story.lj
[root@heaven TeX]#
The default is to create a file in PCL format with the extension ".lj", which can be printed on a any laser printer.
Solutions to some printing problems
lpr or LPRng under Linux requires the presence of the "lpd" print daemon and a correctly configured "/etc/printcap" file. You then must print with "lpr" or some common program like StarOffice, Communicator, etc.

Nevertheless, creating temporary files, sending the print to the device, the presence or absence of "lo" (local loopback) can temporarily block printing.
You have to look at the active services to determine what happened if a print didn't finish satisfactorily.
If it's not active, you need to:
If "lp" is present, you can install the local
printer, with printool
Block devices:
2 fd
3 ide0
22 ide1
[root@world /proc]#
Otherwise you need to include the relative drivers in the kernel.
In Linux 2.4.2, you need to activate the following:
![]() |
![]() |
| This mask belong to the "Parallel port support" in the main Menu | Then, you need enable "Parallel printer support" in "Character devices" |
[root@ftosx1 /root]# more /proc/devices
Character devices:
1 mem
2 pty
3 ttyp
4 ttyS
5 cua
6 lp
7 vcs
10 misc
14 sound
81 video_capture
128 ptm
136 pts
162 raw
180 usb
Block devices:
2 fd
3 ide0
22 ide1
[root@ftosx1 /root]#
[root@heaven /root]#
You can run a test print by explicitly sending a file to the device with the command: "cat /etc/passwd > /dev/lp0".
RedHat Linux includes also the "lptest" program. Another test can be "lptest > /dev/lp0"
Check the Interactive Exam Cram BASE:
Internet Resources for this chapter.