Can we limit the number of active jobs on a given printer?

Helge Blischke h.blischke at acm.org
Sat Jun 19 02:15:58 PDT 2010


Kai Lanz wrote:

> 
>> As you backend is a shell scrip, please post (an URL to) it. When looking
>> into it, perhaps a (partly) solution might come to my mind ...
> 
> Here it is. For brevity, I've removed our boilerplate comments and some of
> the error-checking code.
> 
> ---
> 
> #! /bin/sh
> 
> qname="BINPS"
> domain="stanford.edu"
> 
> DB_DIR=/var/adm/printerdb
> 
> if [ $# -eq 0 ]; then
>     echo "direct qcsendpr \"Unknown\" \"Send data to printer via LPRng.\""
>     exit 0
> fi
> 
> if [ $# -ne 5 -a $# -ne 6 ]; then
>     echo "Usage: qcsendpr jobid user title copies options [file]"
>     echo "  Example for device-URI: 'qcsendpr:escher'"
>     echo ""
> fi
> 
> FILE=$6 || FILE="-";
> 
> printer=${DEVICE_URI#qcsendpr:}
> 
> # Has the current top job been released for printing?
> #
> # Get the job_id number of the first job in the queue for this printer:
> 
> job=`/usr/local/bin/mylpq $printer | /usr/bin/head -1 | /bin/cut -d' ' -f
> 2`
> 
> # Search DB file to see if this job is listed
> 
> /bin/egrep -q ^[\ ]*$job" " $DB_DIR/$printer.db
> grepstatus=$?
> 
> # If the job has been released, pass it to LPRng lpr via the usual filter
> # pipeline.
> # dosprstrip: remove leading ctrl-D if present
> # hppjlstrip: remove HP PJL header and trailer if present
> # LPRng options: -k = do not create a temp file; send direct to printer
> #                -Y = do not spool; send direct to printer
> 
> if [ $grepstatus -eq 0 ]; then
>     /bin/cat $FILE | /usr/local/etc/dosprstrip | /usr/local/etc/hppjlstrip
>     | \
>         /usr/bin/enscript -B -h -p- -q -Z | \
>         /usr/local/sbin/lpr -h -Y -k -P ${qname}@${printer}.${domain}
> 
> # Now flag the job as printed in the DB file by appending a "p" to the
> # job number (this ensures it will not match future jobs).
> 
>     /bin/sed -e "s/\(^[\ ]*\) ${job} /\1${job}p /" $DB_DIR/$printer.db >
>     $DB_DIR/$printer.db.new /bin/mv $DB_DIR/$printer.db.new
>     $DB_DIR/$printer.db /bin/chmod 664 $DB_DIR/$printer.db
>     exit 0
> 
> else
> 
> # If the current top job in the queue hasn't been released for printing,
> # stop the queue and exit with "failed" status so job will remain in
> # queue:
> 
>     /usr/bin/cupsdisable $printer
>     exit 1
> fi

If I interprete your /usr/local/sbin/lpr command correctly, the "-Y -k" 
prevents spooling on the local client but not on the host that manages the 
printers itself.
Thus, your backend exits if the print job has successfully transferred to 
the print server. Assuming that the printserver uses LPRng as well, you need 
to implement a lpc loop to check if the job has been printed successfully.

Maybe my assumprions are not correct - perhaps you could supply more 
information on your configuration.

Helge






More information about the cups mailing list