LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-02-2008, 04:56 PM   #1
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Rep: Reputation: 23
Question 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!
 
Old 12-02-2008, 07:58 PM   #2
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by slinx View Post
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
 
Old 12-03-2008, 12:31 PM   #3
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Original Poster
Rep: Reputation: 23
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?
 
Old 12-03-2008, 12:46 PM   #4
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by slinx View Post
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
 
Old 12-03-2008, 03:56 PM   #5
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Original Poster
Rep: Reputation: 23
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.
 
Old 12-03-2008, 04:24 PM   #6
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by slinx View Post
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) ?
 
Old 12-03-2008, 06:23 PM   #7
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Original Poster
Rep: Reputation: 23
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>
 
Old 12-03-2008, 06:47 PM   #8
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by slinx View Post
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.
 
Old 12-03-2008, 07:05 PM   #9
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Original Poster
Rep: Reputation: 23
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.
 
Old 12-03-2008, 07:13 PM   #10
pcunix
Member
 
Registered: Dec 2004
Location: MA
Distribution: Various
Posts: 149

Rep: Reputation: 23
Quote:
Originally Posted by slinx View Post
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..
 
Old 12-04-2008, 03:45 PM   #11
slinx
Member
 
Registered: Apr 2008
Location: Cleveland, Ohio
Distribution: SuSE, CentOS, Fedora, Ubuntu
Posts: 106

Original Poster
Rep: Reputation: 23
Hey Tony, thanks for your help. I ended up modifying a pdf backend script to print to a text file, and it works.
 
  


Reply

Tags
cups, curl, lp, perl, printing, text



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't call method "title" on undefined title in Perl script scuzzman Programming 12 12-11-2009 04:40 AM
Errors when running Perl script in a cron job meshach Slackware 2 06-20-2006 09:10 PM
Trouble with perl script in Cron job thack111 Linux - General 7 11-25-2004 02:44 AM
job title? amadkow General 18 08-13-2004 02:05 PM
Job Title? patpawlowski General 6 01-28-2004 08:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration