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

Dual printing

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© December 2007 Anthony Lawrence

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 "[email protected]"
lp -d printer2 "[email protected]"
lp -d printer3 "[email protected]"
 

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:,

#!/bin/bash
# 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:

#!/bin/bash
# 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:

#!/bin/bash
# don't leave off the first line - absolutely needed for cups!
for i in "[email protected]"
do 
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:

threeprint-7
root
 
2
landcape
/tmp/t
 

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

509
apl
t
2
finishings=3 number-up=1 landscape job-uuid=urn:uuid68d98a7c-87da-3f42-61ec-7726392ebb14
/private/var/spool/cups/d00509-001
 

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.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Dual printing

8 comments


Inexpensive and informative Apple related e-books:

iOS 8: A Take Control Crash Course

Take Control of Apple Mail, Third Edition

Take Control of High Sierra

Take Control of Upgrading to El Capitan

Take Control of the Mac Command Line with Terminal, Second Edition





More Articles by © Anthony Lawrence







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

gravatar


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

gravatar


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







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

gravatar


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

gravatar


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







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

gravatar


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

gravatar


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

gravatar


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

gravatar


Does the script work outside of CUPS?





------------------------


Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





That's the thing about people who think they hate computers. What they really hate is lousy programmers. (Larry Niven)




Linux posts

Troubleshooting posts


This post tagged:

Linux

Printing

Shell

Unix



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode