Sometimes you want a person's default printer to be different
than someone else's (the default printer is the one that gets used
when you just use "lp" by itself). One way to control that is with
LPDEST (Sys V) or PRINTER (Cups). For example, the following lines in .profile (using PRINTER for .bash_profile and Cups) will set the
default differently when logging in on different tty's:
DEFPRINT=`tty | sed 's/.dev.tty//'
LPDEST=biglaser; export LPDEST
case $DEFPRINT in
This assumes that the port being used determines the persons
physical location. Sometimes you need to be even trickier than
that, or you want to change multiple "printers" at the same time.
Consider the case where you have multiple offices, but you want to
have your software just use "checks" and "forms" so that the
choices it presents aren't cluttered with entries like "la_forms",
"denver_checks", etc. To do this, you need to front-end the lp
program itself- you have a script that pretends to be "lp", but it
decides where the job should really go and passes that to the real
"lp" program. When it saw a request to print to "forms", it would
decide what real printer to send to, and re-route it appropriately.
Here's a post from Bill Vermillion describing a similar idea:
From: Bill Campbell <firstname.lastname@example.org>
Subject: Re: How do I set default printers?
Content-Type: text/plain; charset=us-ascii
Organization: [resent by] The SCOMSC gateway and Propagation Society
Date: Fri, 28 Apr 2000 18:17:50 GMT
In-Reply-To: <email@example.com>; from firstname.lastname@example.org on Fri, Apr 28, 2000 at 10:52:04AM -0700
References: <nYhO4.9849$9A6.email@example.com> <yJjO4.10289$9A6.firstname.lastname@example.org> <email@example.com>
Sender: firstname.lastname@example.org (xenitec.on.ca News Administrator)
Xref: news.randori.com comp.unix.sco.misc:59126
On Fri, Apr 28, 2000 at 10:52:04AM -0700, Jeff Liebermann wrote:
>On Fri, 28 Apr 2000 17:18:22 GMT, "jmt" <email@example.com> wrote:
>>I forgotten to mention if the running application has the printer name
>>hardcoded into there application to which printer to print to, how can I
>>change that printer? I know what the printer name is, just need to redirect
>>there print job to another printer name.
>If your unspecified application has something like:
> lp -d printer_name
>imbedded in some configuration file, then you're stuck. It takes priority
>over $LPDEST and over the print spoolers default printer.
>However, I know of no application, written by mortals, that cannot be
>twisted into doing what I want it to do. First, find the configuration file
>that goes with your unspecified application, and see if you can find the
>place where the printer is defined. If it looks like:
I have a system that does exactly that. I have a file, /etc/printers
that has entries mapping logical printer names to real printer names,
and the system on which to print them. The file looks like this:
default laser localhost
laser laser localhost
oldprn printer someotherhost
I then have /usr/local/bin/lp that's in the PATH before /usr/bin/lp
and further I move the original /usr/bin/lp to /usr/bin/lp.original,
and link it to /usr/local/bin/lp to make sure that everybody uses it.
My script then reads the /etc/printers file, and maps the printer name
to the real printer. If the printer's local, then it forwards the job
to the local with a pipe to ``/usr/bin/lp.original -ddestination''.
If it's a different system, then it pipes to the remote system using:
"|ssh someotherhost /usr/local/bin/lp @ARGV"
This is in perl so it passes the appropriate arguments to the remote
system's /usr/local/bin/lp program which goes through exactly the same
process. It would even be possible to have the job get in a loop if
each system redirected the job to the other (I suppose this could be
done intentionally if there were a printer problem, breaking the loop
when the printer was working again :-).
The code you use to decide where to re-route can be as simple or
as complex as you need it to be. It can be based on the serial
port, or you could have exported an environment variable. You might
even need to ask the user in their .profile which "set" of printers
they want to use, or where they are presently located. Store that
information in a variable and export it.