Technical article 111722

How do I automatically remove all the print jobs in my print queue?

OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.3UnixWare 7.1.4

Written · Last revised

Problem

How do I automatically remove all the print jobs in my print queue?

Solution

Use the following script which can remove all the print jobs on all queues, by default, or you can specify a file which will contain a list of printers in the format:

printer1
printer2
etc
:
#
# Variables
#
TMPDIR=/tmp export TMPDIR
PURGE_DIR=/local/lib export PURGE_DIR
PURGE_LIST=$PURGE_DIR/purge_print_list export PURGE_LIST
#
# Existence
#
if [ ! -d $PURGE_DIR ]; then
        echo "ERROR: $PURGE_DIR does not exist !"
        exit 1
fi
        #
        # Process each printer on the queue
        #
        if [ ! -s $PURGE_LIST ]; then
                lpstat -p | awk '{print $2}' > $PURGE_LIST
                CLEAR="Y"
        else
                CLEAR="N"
        fi
        for i in `cat $PURGE_LIST`
        do
                echo "Checking $i for prints ... "
                while true
                do
                        #
                        # If the output to the file is greater than zero then
there
                        # are prints waiting.
                        #
                        lpstat -o $i > $TMPDIR/$i.out
                        if [ -s $TMPDIR/$i.out ]; then
                                #
                                # Cancel the print and tidy up
                                #
                                cancel $i
                                rm -f $TMPDIR/$i.out
                        else
                                #
                                # If the file is empty then time to move on
                                #
                                break
                        fi
                done
                #
                # Tidy Up
                #
                rm -f $TMPDIR/$i.out
        done
        if [ "${CLEAR}" = "Y" ]; then
                rm -f $PURGE_LIST
        fi

It is recommended that you install these Network Printing supplements:

SCO UnixWare 2.1.3:  SLS ptf4030
UnixWare 7:  SLS ptf7438

See also

ta103239, "How do I cancel multiple print jobs on UNIX and XENIX?"

From the Xinuos technical article database, record 111722. Reproduced with permission. The original is at www.sco.com/ta/111722, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.