Operating System - HP-UX
1834480 Members
3441 Online
110067 Solutions
New Discussion

Re: Pipe for multiple printer!

 
Fragon
Trusted Contributor

Pipe for multiple printer!

Print a text file to one printer, it is easy!
# more $$.txt|lp -d lj5_1
But I want to print this file to multiple printer , how to?
Note that pipe-use is necessary because $$.txt file is generate from an application and is temporary.
===================================
The following is the reason why I must do this!
I have an application! I setup the printer in the application like this:

Printer-Name UNIX-Command
lj5acc lp -d lj5_1 -onb
lj5pur lp -d lj5_2 -onb

When selecting the printer, I can only select lj5acc or lj5pur. I guest it print the job use pipe like this:
# cat jobs|lp -d lj5_1 -onb
Now one user request that he must print his file to lj5_1 & lj5_2, so how can I make "UNIX-Command" for this task?

Very sorry for my poor English!
5 REPLIES 5
Michael Schulte zur Sur
Honored Contributor

Re: Pipe for multiple printer!

Hi,

my suggestion, if works the way you think.

#!/bin/ksh
> /tmp/${$}.tempout
while read LINE
do
echo ${LINE} >> /tmp/${$}.tempout
done
lp -d printer1 /tmp/${$}.tempout
lp -d printer2 /tmp/${$}.tempout
lp -d printer3 /tmp/${$}.tempout
rm /tmp/${$}.tempout

if the programme just uses lp -d lj5_1 -onb
with the file to print as parameter:
#!/bin/ksh
lp -d printer1 ${1}
lp -d printer2 ${1}
lp -d printer3 ${1}


greetings,

Michael
Fragon
Trusted Contributor

Re: Pipe for multiple printer!

Hi Michael , thank you very much for your reply!
But I think it won't work!
When use a shell program , it will replace the whole shell to the "UNIX-Command" , just like this:
# more jobs|#/usr/bin/ksh while read ....
Of course this can't work!
I'm not sure if this will work:
# more jobs|lp -d lj5_1|lp -d lj5_2

Any other ideas ?
Thank in advanced!
Michael Schulte zur Sur
Honored Contributor

Re: Pipe for multiple printer!

Hi,

why do you think, it copies the contents of the file to the command line? It cant do it with the lp command, because thats a binary file. Anyway, you may try to trick it by using two shells. One you specify in the configuration, which has just one line:
. ./second_script
In case it copies the contents of the first script, it gets only this line and the rest is in script 2.

have fun,

Michael
Leif Halvarsson_2
Honored Contributor

Re: Pipe for multiple printer!

Hi,

I can't find any way to specify multiple printers from the command line. My first idea was if "tee" could be used but, it only works with files. There is an enhanced version of tee (xtee) avialable as freeware which can use pipelines. I have not used it myself but it may be an idea.

http://chasseur.usc.edu/pups/manPages/pupsManPages/xtee.1.html#lbAB
Jordan Bean
Honored Contributor

Re: Pipe for multiple printer!

Hi Z,

Define a new application printer definition for both unix printers that uses the script below.

printer-name unix-command
lp5acc-pur /path/to/script '-dlp5acc -o"nb land c"' '-dlp5pur -onb -oland -oc'

Yes, each printer name and its options are single-quoted together... Do not forget to use -d and -o appropriately. Notice how the options of the first printer are double-quoted within the single-quotes. The second printer separates its options so double-quotes are not needed.

The script:

#!/usr/bin/sh
mytmp=/tmp/${0##*/}.$$
trap "rm -f $mytmp" EXIT
cat - > $mytmp
if [ -s $mytmp ]
then
for p in "$@"
do
eval lp $p $mytmp
done
fi

To preserve the quoting of each printer argument, it is important to double-quote "$@" in the for loop and to use eval to prepare the commandline for lp.

Notice that "cat" is used to slurp the standard input to a temp file. This means that the script is intended to be used in a pipeline, or a single file must be redirected as standard input.