LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to read the lp job title from a Perl backend script? (https://www.linuxquestions.org/questions/linux-software-2/how-to-read-the-lp-job-title-from-a-perl-backend-script-687846/)

slinx 12-02-2008 04:56 PM

How to read the lp job title from a Perl backend script?
 
I'm using the instructions from here to set up a TEXT-to-file printer.

I'm using CUPS.

How do I get the job title parameter from the lp command, so I can incorporate it in the output file?

Thanks!

pcunix 12-02-2008 07:58 PM

Quote:

Originally Posted by slinx (Post 3362308)
I'm using the instructions from here to set up a TEXT-to-file printer.

I'm using CUPS.

How do I get the job title parameter from the lp command, so I can incorporate it in the output file?

Thanks!

Job title is the third parameter ($3) (usually not set though)

Hope you read the comments as the article itself is the HARD way as the title says.

--
Tony Lawrence
http://aplawrence.com

slinx 12-03-2008 12:31 PM

Thanks Tony, I did check the comments - the perl script seems to work nicely though.

We need a way to put the job title in the output file - is there a way to do it with the parallel port trick?

pcunix 12-03-2008 12:46 PM

Quote:

Originally Posted by slinx (Post 3363270)
Thanks Tony, I did check the comments - the perl script seems to work nicely though.

We need a way to put the job title in the output file - is there a way to do it with the parallel port trick?

No, you'd need to do it in a "backend" or a Sys V script. You'd just pick up $3 and do whatever you want with it.

Examples of backend scripts are all over the web - google "cups backend".
Sys V scripts: http://aplawrence.com/Unixart/cups_sysv_interface.html

slinx 12-03-2008 03:56 PM

Thanks, I tried that, but I can't get it to write anything.

Here's my script:
Code:

#!/bin/bash

job_title=$3
shift;shift;shift;shift;shift

print_dir=/var/www/html/remoteprint
print_date=$(date +%Y-%m-%d_%R)
print_file=$print_dir/$print_date.$job_title

cat $* > $print_file

Well I know it's not right... but what do I need to do, to get it to pass stdin into the output file, named with the job title? It doesn't do anything right now.

pcunix 12-03-2008 04:24 PM

Quote:

Originally Posted by slinx (Post 3363485)
Thanks, I tried that, but I can't get it to write anything.

Here's my script:
Code:

#!/bin/bash

job_title=$3
shift;shift;shift;shift;shift

print_dir=/var/www/html/remoteprint
print_date=$(date +%Y-%m-%d_%R)
print_file=$print_dir/$print_date.$job_title

cat $* > $print_file

Well I know it's not right... but what do I need to do, to get it to pass stdin into the output file, named with the job title? It doesn't do anything right now.

Are you sending the title (-t) ?

slinx 12-03-2008 06:23 PM

Yes, I am. My lp command looks like
Code:

lp -d TEXT -t CUPSD /etc/cups/cupsd.conf
(just using cupsd.conf as a sample file to print)

Now, I set up my printer to send the output to /dev/null, because the interface should handle sending the data to the file, right? Or do I need to do something different? Here is my printer definition:
Code:

<Printer TEXT>
Info TEXT
DeviceURI parallel:/dev/null
State Idle
Accepting Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>


pcunix 12-03-2008 06:47 PM

Quote:

Originally Posted by slinx (Post 3363588)
Yes, I am. My lp command looks like
Code:

lp -d TEXT -t CUPSD /etc/cups/cupsd.conf
(just using cupsd.conf as a sample file to print)

Now, I set up my printer to send the output to /dev/null, because the interface should handle sending the data to the file, right? Or do I need to do something different? Here is my printer definition:
Code:

<Printer TEXT>
Info TEXT
DeviceURI parallel:/dev/null
State Idle
Accepting Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>


No, the interface doesn't need to handle the destination. It just needs to add the title.

slinx 12-03-2008 07:05 PM

What do I need to have in the interface to pass the title? Where do I define my output title?

I originally had set up a text printer to print to a file, in this case /usr/archives/txtrpts/report.prn

But we discovered that when multiple users tried to print to the same file, their lpr processes would hang. So I'm trying to write something that won't hang because multiple users are trying to write to the same file simultaneously.

I might just go back to the Perl server listening on a socket, at least I could get that to produce some output...

Thanks for your help.

pcunix 12-03-2008 07:13 PM

Quote:

Originally Posted by slinx (Post 3363620)
What do I need to have in the interface to pass the title? Where do I define my output title?

I originally had set up a text printer to print to a file, in this case /usr/archives/txtrpts/report.prn

But we discovered that when multiple users tried to print to the same file, their lpr processes would hang. So I'm trying to write something that won't hang because multiple users are trying to write to the same file simultaneously.

I might just go back to the Perl server listening on a socket, at least I could get that to produce some output...

Thanks for your help.

Definitely the direct to file is not suitable for multi-user.

There were other pointers in the comments that might help.

Sure was a lot easier with Sys V interface scripts..

slinx 12-04-2008 03:45 PM

Hey Tony, thanks for your help. I ended up modifying a pdf backend script to print to a text file, and it works.


All times are GMT -5. The time now is 01:22 PM.