UNIX is a multi-user network operating system, so it specializes in sharing devices and resources. The simplest way to do this is with the most uncomplicated elements necessarily, such as with simple text files. It's hard to break a simple text file, and even if something did happen to it, it's easy to fix. That's why UNIX systems have depended on it for configuring servers, such as print servers.
The central printing program on UNIX systems is a print server,
also called a ``spooler,'' that usually goes by the name
lpd. Unlike a single-user system, UNIX expects to share
many devices with many people that might be spread out over a
large area. To accommodate this requirement, lpd can
handle many shared printers (over a network) with many print jobs
from many people, all at the same time.
Since multiple users and multiple jobs are expected, each printer
has a print queue that lpd keeps watch over. In fact, any
UNIX machine may run lpd, regardless of whether it has a
printer attached. For instance, in my home network, I have 12
machines and three printers connected. All internal machines run
lpd. Thus, I can print from any machine across the
network to any machine that has a printer attached. The
lpd on one machine talks to the lpd on the machine
with the desired printer attached, and all jobs get handed off
correctly. This is called remote printing.
After you've physically connected your printer to your print
server (which is what the box you connect your printer to will
become), you just need to print a test page to see that that
connection is okay. Try lptest | /dev/lp0 if that exists
on your system.
/etc/printcap. The configuration file for the printer daemon is normally /etc/printcap. It has a rather simple syntax, once you know what the abbreviations mean. And, fortunately, you only really need to know about five or six of the abbreviations for most configurations. Most configuration files come with sample configurations commented out so you can uncomment one that applies to your needs and customize as needed.
There are basically two types of printers, as far as lpd
is concerned: local and remote. Your default /etc/printcap will
most likely already contain entries for both that are commented
out. You will probably only need to change a few values so you
can be off and running.
Assuming you have multiple hosts you'll be working with, you first configure the printcap file on the print server, restart that daemon, then configure the client printcaps and restart their respective daemons. Here's a sample printcap file:
#sample local printer entry lp|deskjet:\ #name of local printer :lp=/dev/lpt0 #name of device :sd=/var/spool/output/lpd #name of spool directory :lf=/var/log/lpd-errs #name of log file :mx#0 #don't limit size of doc :sh: #suppress headers #sample remote printer entry disney | color_printer:\ #name printer goes by :lp= #blank field: non-local device :rm=host1 #name of host connected to prtr. :rp=disney #name printer goes by on host :sd=/var/spool/output/lpd #local spool directory :lf=/var/log/lpd-errs #local log file :mx#0 #don't limit size of doc :sh: #suppress headers on #sample additional remote printer entry laserjet | epson:\ #name printer goes by :lp= #blank field: non-local prtr. :rm=host2 #name of host connected to prtr :rp=laserjet #name printer goes by on host :sd=/var/spool/output/lpd #local spool directory :lf=/var/log/lpd-errs #local log file :mx#0 #don't limit size of doc :sh: #supress banners
Notice above how you can almost get away with just knowing lp, sd, lf, rm, rp, and sh. Notice also that you must supply the actual hostname for remote printers for the ``rm'' parameter. If that host's name is ``Wally'' on your network, then put that. If ``Beaver'', put that instead. Just use the hostname, not the fully qualified domain name, such as wally.myhome.net.
For all those I have ommitted, please see man printcap.
Print Filters. When you stop and think about it, there are many many different types of documents that the everyday printer is expected to print. Consider all the different types of graphic formats, the different document types, the different compression types. Consider the different types of applications all printing to the same printer. They're all expected to chatter away with no complaints despite their very different natures. Well, it's too much to ask a single server to handle all these different types of formats, so we solve this problem with print filters. You queue a file to the printer, and before it actually gets to the printer, a filter translates it into something the printer can actually understand. All this, of course, is transparent to you unless you're the lucky one to configure it.
Several filters exist but one of the most common is called apsfilter (www.apsfilter.org). It might well be installed on your system already. Or it might be called something else on your system. When you install it, it will run a setup program that asks for information about your printer and modifies your /etc/printcap file accordingly. Once it's configured properly, you'll be able to print the supported types of files from all your various applications.
Another approach for configuring printing under UNIX is called ``CUPS.'' See www.cups.org. It will probably make all what I'm talking obsolete one day. Until then, it can't hurt to understand how to configure your printer by hand.
Restarting the Daemon. After you modify
/etc/printcap, you will likely need to restart lpd. Your
version of apsfilter might have done this already. How you
restart the printer daemond depends on your system, but a
rootshell with kill HUP `pidof lpd` should do it for you.
Note: on non-SysV systems, try
$(killall -s -d $1 | cut -d ' ' -f 3) for ``pidof''.
Now, you should be in business. If something seems amiss, be
sure you read the logs in /var/log, or wherever your logs
happen to be. Remember, your log file will be whatever file you
specified in /etc/printcap with the ``lf='' value.
Remote Printing. What I've described is well and fine if you're printing locally. But what if you want to use a printer that isn't connected to your own computer?
If you look at the /etc/printcap file that already exists on your
system, you probably already have an entry for a remote printer.
Usually, the printcap file assumes you have a local printer,
called lp, and a remote printer by some other name. If
you don't have a local printer, you can rename the entry for your
remote printer and call that lp.
For example, on my network, the printer I print most often to is
called simply lp. If I want to print to another printer,
I must specify it with the -Pprintername switch that
I pass to the lpd program:
lpr -Pnextprinter file2prt
My printcap entry looks like this:
lp:lp=:rm=sylvester:rp=lp:sd=/var/spool/output/sylvester:lf=/var/log/lpd-errs:sh
Where sylvester is the host the remote printer is connected
to, the logfile is /var/log/lpd-errs, and the local spool directory
is /var/spool/output/sylvester.
Remote printing can present a security risk to your network.
Therefore, be certain that you have your print server closed off
to print requests from outside your local network, or even from
hosts on your network that you don't want to give permission to
print. Pay attention to your TCP Wrappers, since you might have
to include the allowed hosts you want to print from in your
/etc/hosts.allow or /etc/hosts.equiv file on your
print server. Make sure your firewall blocks remote print
requests originating outside your network.