lp -c to print temporary print files



I've had the most bizarre experience with the lp command on AIX 6.1.

We have an application which prints files by writing to a temporary
directory, calling lp -c <filename>, then remove the file.

To date, I've always understood the -c flag to mean copy the file
before printing, which sounds good since there might be a race
condition where the print subsystem attempts to read from the original
file to do the printing.

So this script fragment should work:
lp -c /tmp/filename.txt.$$;rm -f /tmp/filename.txt.$$

However we've been getting error write messages from the printer
daemon to say the file's not there, giving me my usual puzzled facial
expression since that was the whole point of the "-c" flag, wasn't it?

As it turns out, whether you use -c or not, the lp command does not
read the file itself, but (probably) checks the file exists, then
sends the filename to the print subsystem and then quits.

The functional difference is that with "-c", the job would be printed
from somewhere in /var/spool, while without "-c", the job would be
printed from the original targeted file.

However practically it has very little difference; in either case the
lp command quits, allowing the script to run the rm command
immediatly, opening up the race condition that the file gets deleted
before the queue subsystem gets to print the file.

Printing from standard input would have to spool the file first and
then quit, so that seems safe.

Looking at the man page for lp actually says "when using -c, be
careful not to remove any of the files before they are printed",
suggesting that the problem doesn't exist if you leave off the "-c"
flag?

The man pages for enq and lpr have "-r" options, saying "-r" remove
file after spooled" for lpr (sounds good) and enq -r to remove file
after successfully printed, which doesn't sound as good because I wont
want to have to start writing cleanup scripts.

So have I got this wrong? Is this a bug or just a feature that will
continue to annoy me for years to come?

Regards
Bj
.



Relevant Pages

  • Re: Great SWT Program
    ... (and has a command to toggle display of markup, ... unlike Java's for and while syntax. ... Writing a script to strip the ... prose in a very artificially consistent sort of way, ...
    (comp.lang.java.programmer)
  • Re: minimum valid block size on DVD-RAM
    ... size accepted by DVD (writing) devices when writing ... a DVD-RAM is, like on nearly all other DVDs and CDs, ... I'd now like to know whether most of the available DVD-writers ... Please report me whether command 3 and command 2 succeed ...
    (freebsd-questions)
  • minimum valid block size on DVD-RAM
    ... size accepted by DVD (writing) devices when writing ... a DVD-RAM is, like on nearly all other DVDs and CDs, ... I'd now like to know whether most of the available DVD-writers ... Please report me whether command 3 and command 2 succeed ...
    (freebsd-questions)
  • Re: Great SWT Program
    ... (and has a command to toggle display of markup, ... have to consult the documentation for my shell of choice. ... and a particularly hairy syntax for distinguishing variables ... Writing a script to strip the ...
    (comp.lang.java.programmer)
  • AWK in a column help
    ... I am writing a script that will return ONLY one output per command and then move on to the next line ... Typically,I want the script to list the first item in the display such that each command returns one value only as in my example below ... Basically i am checking the log file for a string "PLACED" then picking the values i want using AWK..it seems to work fine but i want to list each output one EACH TIME rather than listing ALL. ...
    (comp.unix.shell)