lp -c to print temporary print files
- From: bj <ben.kuit@xxxxxxxxx>
- Date: Mon, 6 Dec 2010 18:23:37 -0800 (PST)
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
.
- Follow-Ups:
- Re: lp -c to print temporary print files
- From: sjm
- Re: lp -c to print temporary print files
- Prev by Date: AIX System Engineer needed in Michigan
- Next by Date: nohup scp ... & ### scp bug?
- Previous by thread: AIX System Engineer needed in Michigan
- Next by thread: Re: lp -c to print temporary print files
- Index(es):
Relevant Pages
|