APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Dual printing

© Anthony Lawrence, aplawrence.com

Multiplexed printing is missing from all Unix/Linux printing systems that I know of. If you want to print to printer "Main" and have the output appear on two different physical printers, there's no way to specify that when creating "Main".

I don't mean printer classes, where you want "Main" to pick an available printer from a pool. I mean where you want one print command to appear on two or more physical devices.

Obviously you could do this with a simple shell script:

lp -d printer1 "$@"
lp -d printer2 "$@"
lp -d printer3 "$@"

If you called that "threeprint", you could say "threeprint myfile" and you'd get it on all three printers. You'd need to remember to do that though, and it could be difficult to convince some application programs to use your script instead of "lp".

You could "front-end" lp. That is, you could replace the system lp with your own script that parses the arguments and normally just passes them on to the original lp command that you have hidden away somewhere, but watches for a special printer name and handles that by sending it to multiple printers. That can work, but system upgrades would break it easily, and you have to parse arguments carefully in your script.

So, what we really want to do is make lp do the work for us. With System V printing, that's very easy, and since Cups can use Sys V interfaces, we can use the same script on Linux and Mac OS X.

The script itself can be very simple if you don't care about optional parameters. That's often the case when the "printer" will only be used by some application that won't pass any options like number of copies or orientation. If that's true, something like this will work:,

# if you don't have bash, use /bin/sh
# don't leave off the first line - absolutely needed for cups!
/usr/bin/lp -dprinter1  $6
/usr/bin/lp -dprinter2  $6
/usr/bin/lp -dprinter3  $6

For SysV and Cups, that's your "interface" file. You'd create a new printer like this:

# System V
chmod 755 ~/myinterfacefile
cp   ~/myinterfacefile  /var/spool/lp/model
/usr/lib/lpadmin -p threeprint -m myinterfacefile  -v /dev/null
/usr/lib/accept threeprint
enable threeprint 

There's a little less work for Cups:,

# Cups
chmod 755 ~/myinterfacefile
lpadmin -p threeprint -E  -i ~/myinterfacefile -v /dev/null

Sending jobs to "threeprint" (lp -d threeprint somefile) will now print on all three printers. If you did need to process the number of copies to print, the script isn't much different:

# don't leave off the first line - absolutely needed for cups!
/usr/bin/lp -dprinter1  -n$2 $6
/usr/bin/lp -dprinter2  -n$2 $6
/usr/bin/lp -dprinter3  -n$2 $6

However, after that, there are differences between System V and Cups. The easiest way to see these is to add a little logging function to our script:

# don't leave off the first line - absolutely needed for cups!
for i in "$@"
echo $i
done > /tmp/mylogfile
/usr/bin/lp -dprinter1  -n$2 $6
/usr/bin/lp -dprinter2  -n$2 $6
/usr/bin/lp -dprinter3  -n$2 $6

Let's test it out:

date > /tmp/t
lp -dthreeprint -n2 -o landscape /tmp/t

On System V printing, we'll end up with something like this in our log:


On Cups, it's different. This was from my Mac OS X machine:

finishings=3 number-up=1 landscape job-uuid=urn:uuid68d98a7c-87da-3f42-61ec-7726392ebb14

We have everything we need, but some of it is in different variables, so we'd need to write the script differently.

I know someone is bound to ask "Why didn't you use a backend script?". You absolutely could, but that involves putting the script into /usr/libexec/cups/backend/ and restarting cups. As we aren't doing a darn thing that needs any other functionality we could get with a backend script, why go to all that trouble? The interface file method works just as well, and requires no restart of Cups.

See Using System V interface scripts with CUPS printing also.


More Articles by

Find me on Google+

Anthony Lawrence

Click here to add your comments
- no registration needed!

Thu May 20 04:31:35 2010: 8620   anonymous


Hi! I tried the tutorial, but when I try to print something, a printer error telling me that: "There was a problem procesing document 'myinterface' (job #)"

Thu May 20 10:34:59 2010: 8621   TonyLawrence


It's impossible to help you with so little information.

Mon May 23 17:49:08 2011: 9503   Josh


I feel like I am pretty close to getting this script to work. I run all of the commands with no errors, until I try to print to the newly created queue. The command line shows "request id is ...." but no error. When I go to the new queue, it shows status of "Error". Under "Printer Ready" it states "You need to install software to use this printer..."

I have tried using both bash and sh in the script as well as both lp and lpr.

I am running OSX 10.6.7 w/CUPS 1.4.6

Any advice would be hugely appreciated. Thanks!

Mon May 23 18:07:51 2011: 9504   TonyLawrence


What kind of printer? Without that, it is impossible to guess.

Mon May 23 18:12:41 2011: 9505   Josh


I am testing using a networked(over windows share) Epson Workforce 310 printer. In the end I just need to see it hit the other two printer queues. I'm working on a project where I need to print to two printers at the same time. The printers will be different, but I need to find a solution to this.

I've found some 3rd party options, but they are all Windows only.

It seems to me there should be a "broadcast option" for a printer pool/class.

Thanks for your help!

Mon May 23 18:19:19 2011: 9506   TonyLawrence


If it's a Windows shared printer, you have to use Samba to print to it OR set it up as a lpd printer in Windows (see (link) )

Once you have the base printer working, then come back to this so that the dual print can work.

Mon May 23 20:02:47 2011: 9508   Josh


I think I misspoke as to the actual problem. I can print to the two printers individually. The problem is with the script sending the print job to the printers. When I try to print to "threeprint" it gives an error saying you have to install the software. (for the System V printer).

Would I need to modify the interface file as I am using OSX?

Thanks again!

Mon May 23 20:11:21 2011: 9509   TonyLawrence


Does the script work outside of CUPS?

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
Kerio Samepage

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.

Contact us

Jump to Comments

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.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

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.

This post tagged: