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 A0[1-8]) LPDEST=printer_7;; A09) LPDEST=accounting;; 0[1-9]) LPDEST=console_laser;; B*) LPDEST=ohio;; C*) LPDEST=california;; esac
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:
Newsgroups: comp.unix.sco.misc
Path: news.randori.com!feed2.onemain.com!feed1.onemain.com!isdnet!skynet.be!oanews!info.usuhs.mil!uky.edu!news.xenitec.on.ca!news
From: Bill Campbell <bill@celestial.com>
Subject: Re: How do I set default printers?
Resent-From: mmdf@xenitec.on.ca
Submit-To: scomsc@xenitec.on.ca
Content-Type: text/plain; charset=us-ascii
Reply-To: bill@celestial.com
Organization: [resent by] The SCOMSC gateway and Propagation Society
Date: Fri, 28 Apr 2000 18:17:50 GMT
Message-ID: <20000428111750.A6666@kstarr.celestial.com>
Mime-Version: 1.0
In-Reply-To: <qejjgso6poqtro30i606jfm5sbg8nrijf3@4ax.com>; from jeffl@comix.santa-cruz.ca.us on Fri, Apr 28, 2000 at 10:52:04AM -0700
References: <nYhO4.9849$9A6.55224@typhoon.tampabay.rr.com> <yJjO4.10289$9A6.56093@typhoon.tampabay.rr.com> <qejjgso6poqtro30i606jfm5sbg8nrijf3@4ax.com>
Sender: news@xenitec.on.ca (xenitec.on.ca News Administrator)
Precedence: list
Lines: 55
Xref: news.randori.com comp.unix.sco.misc:59126
X-Mozilla-Status: 8010
X-Mozilla-Status2: 00000000
On Fri, Apr 28, 2000 at 10:52:04AM -0700, Jeff Liebermann wrote:
>On Fri, 28 Apr 2000 17:18:22 GMT, "jmt" <jmtcode@hotmail.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.
/SCOFAQ/FAQ_scotec7defaultprint.html copyright 1997-2003 (various) All Rights Reserved
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar