Making a Printed Copy

It's one thing to create wonderful material in your UNIX account, and another entirely to have it printed. That's what this lesson is all about.

Task 17.1: Find Local Printers with printers

Of the many problems with printing in UNIX, none is more grievous than trying to figure out the names of all the different printers available, what kinds of printers they are, and where they're located. A complicated configuration file—/etc/printcap—contains all this information, but it's definitely not easy to read. So what do you do?


Some systems have an lpstat command, which lists printers available on the system. I find the output of this command difficult to read, hence my inclusion of the printers script here. If you find the output acceptable (see the next task in this hour for a sample), you can skip this first unit, although you still might want to spend a few minutes looking at the printers script anyway.


I will present a simple 20-line shell script, printers, that reads through the /etc/printcap file and creates an attractive and easily read listing of all printers configured on your system. This hour presents the script and shows it at work on a few different computer systems. I encourage you to enter this script and place it in your own bin directory ($HOME/bin should be in your PATH for this to work).

You can get your own copy of this script by popping over to the official Web site of this book, at http://www.intuitive.com/tyu24/.

  1. To start, take a quick look at the contents of the /etc/printcap file:

    % head -23 /etc/printcap
    # $Header: /usr/msrc/usr/etc/printcap/RCS/printcap,v 1.235 93/11/04 10:55:21 mm
    Exp Locker: mm $
    aglwagIwag:
            :dr=/usr/local/lib/lp/lpmq:
            :gc=cc:
            :lf=/usr/spool/lpr/aglw/logfile:
            :lo=/usr/spool/lpr/aglw/lock:lp=/dev/null:
            :mj#25:mx#3000:nd=/usr/local/lib/lp/lpnc:
            :pf=gnpt:
            :rm=server.utech.edu:rw:sd=/usr/spool/lpr/aglw:sh:
            :gf=/usr/local/bin/psplot:
            :nf=/usr/local/lib/devps/devps:
            :qo=age:mq=aglw1,aglw2,aglw3,aglw4:mu:
            :wi=AG 23:wk=multiple Apple LaserWriter IINT:
    aglw1:
            :dr=/usr/local/lib/lp/lwp.sh:
            :gc=cc:
            :lf=/usr/spool/lpr/aglw1/logfile:
            :lo=/usr/spool/lpr/aglw1/lock:lp=/dev/null:
            :mj#25:mx#3000:nd=/usr/local/lib/lp/lpnc:
            :pf=gnpt:
            :rm=server.utech.edu:rw:sd=/usr/spool/lpr/aglw1:sh:
            :gf=/usr/local/bin/psplot:
            :nf=/usr/local/lib/devps/devps:
            :wi=AG 23:wk=Apple LaserWriter IINT:
    

    I won't go into exhaustive detail about the meaning of each field in this listing. It suffices to say that the first line in each entry lists the name of the printer, a | character, and any other possible names for the printer. Each field following the printer name is surrounded by colons and has a two-letter field name (for example, dr, nf), followed by the value of that particular field or setting. The fields of interest are the printer name; the wi field, which indicates the location of the printer; and the wk field, which indicates the type of printer.

  2. There are no UNIX utilities to keep you from having to slog through this configuration file. I have written a short yet powerful C shell script called printers to list the desired information in a readable format:

    % cat bin/printers
    # printers - create a simple list of printers from the /etc/printcap
    #            file on the system.
    #
    # From
    # Teach Yourself UNIX in 24 Hours
    
    set printcap=/etc/printcap
    set awkscript=/tmp/awkscript.$$
    
    /bin/rm -f $awkscript
    
    cat << 'EOF' > $awkscript
    NF == 2 {  split($1, words, "|");
               prname=words[1]
            }
    NF > 2  {  printf("%-10s %s
    ", prname, $0) }
    'EOF'
    
    egrep '(^[a-zA-Z]|:wi)' $printcap | 
      sed 's/:/ /g' | 
      awk -f $awkscript | 
      sed 's/wi=//;s/wk=/(/;s/ $/)/' | 
      more
    
    /bin/rm -f $awkscript
    
      exit 0
    

    Some of this script is beyond what you have learned in this book about commands and scripts. In particular, the awk script, although only four lines long, shows some of the more powerful features of the program. Enter this as shown, and be careful to match the quotes and slash characters. Also, sed, the UNIX stream editor, plays an invaluable role in stripping out the more cryptic and mysterious parts of the printer definition database.

  3. Once you've entered this script, enter the following:

    % chmod +x bin/printers
    							

    That will ensure that it's an executable script. Next, you need to inform the C shell, using the rehash command, that you have added a new command to the search path. Then you can try your new shell script:

    % rehash
    % printers | head -15
    aglw           AG 23 (multiple Apple LaserWriter IINT)
    aglw1          AG 23 (Apple LaserWriter IINT)
    aglw2          AG 23 (Apple LaserWriter IINT)
    aglw3          AG 23 (Apple LaserWriter IINT)
    aglw4          AG 23 (Apple LaserWriter IINT)
    alpslw         LIB 111 (Apple LaserWriter IINTX)
    bio            COM B117 (DataPrinter (self-service))
    cary           CQuad (NE-B7) (IBM 4019 Laser Printer)
    cslw           CS 2249 (Apple LaserWriter IIg)
    cs115lw        CS 115 (IBM 4019 LaserPrinter (for CS180))
    cs115lw2       CS 115 (IBM 4019 LaserPrinter (for CS180))
    csg40lw        CS G040 (IBM 4019 LaserPrinter )
    csg50lw        CS G050 (IBM 4019 LaserPrinter )
    cslp1          CS G73 (C.Itoh, white paper (self-service))
    eng130ci       ENG 130 (C.Itoh, white paper (self-service))
    Broken pipe
    

    You can use this script also to find printers of a certain type or in a specific location, if the descriptions in your /etc/printcap file are configured in the correct manner:

    % printers | grep -i plotter
    knoxhp        KNOX 316A (Hewlett Packard 7550+ Plotter)
    ccp           MATH G109 (CALCOMP 1073 Plotter)
    cvp           MATH G109 (VERSATEC V-80 Plotter)
    % printers | grep -i math
    lwg186        MATH G186 (Apple LaserWriter IINT(private))
    mathci        MATH B9 (C.Itoh, white paper (self-service))
    mathlw        MATH 734 (multiple Apple LaserWriter IINT)
    mathlw1       MATH 734 (Apple LaserWriter IINT)
    mathlw2       MATH 734 (Apple LaserWriter IINT)
    mathlw3       MATH 734 (Apple LaserWriter IINT)
    cci           MATH G109 (C.Itoh, 3 hole white paper)
    ccp           MATH G109 (CALCOMP 1073 Plotter)
    cil           MATH G109 (IBM 4019 Laser Printer)
    cvp           MATH G109 (VERSATEC V-80 Plotter)
    
  4. You now should be able to choose a printer that's most convenient for your location. Set the environment variable PRINTER to that value. You also might want to tuck that into the last line of your .login file so that next time you log in, the system will remember your printer selection.

    % setenv PRINTER mathlw
    % vi .login
    							

If your printer is not responding to what you set the PRINTER variable to, try using the LPDEST variable, especially on System V.


setenv NAME "Dave Taylor"
setenv BIN  "889"

newmail

mesg y
setenv PRINTER mathlw
~
~

The first, and perhaps biggest, hurdle for printing on UNIX has been solved: figuring out what the system calls the printer you're interested in using. Not only do you now have a new command, printers, for your UNIX system, but you also can see how you can customize UNIX to meet your needs by creating aliases and shell scripts.


Task 17.2: Printing Files with lpr or lp

Now that you have identified the name of the printer to use, how about sending information to the printer? If you are on a BSD system, the command to do this is lpr. You can print the results of a pipe command by adding lpr at the end of the pipeline, or you can print files directly by specifying them to the program. You can even use < to redirect input.


If you're using a System V version of UNIX, you will need to use the lp command instead. As you read through this hour, you will see the differences between lpr and lp indicated. Note how the philosophies of the two vary.

The flags available for lpr and lp are numerous, and the most valuable ones are listed in Table 17.1 and Table 17.2. Notice the different meanings of the -P flag in the two commands.

Table 17.1. Useful Flags for lpr
Flag Meaning
-h Do not print the header page.
-i Indent the entire file eight spaces before printing.
-L Print in landscape (sideways) mode, if the printer is capable of doing so.
-Ppr Send the print job to printer pr.
-R Print pages in reverse order.

Table 17.2. Useful Flags for lp
Flag Meaning
-dptr Send the print job to the printer named ptr.
-Pn Print only page n.
-ttitle Use title as the cover page title, where title is any string.

  1. Here's a demonstration of what happens if you try to use lp or lpr without specifying a printer and without having the PRINTER environment variable set. First, use the unsetenv command to remove environment variable definitions:

    % unsetenv PRINTER
    % who  | lpr
    lpr: No printer specified
    Broken pipe
    

    Some systems default to a printer named lp in this situation, so if you don't get an error message, that's what happened. If you have lpstat (a command for checking the status of a printer), the -d flag will result in lpstat listing your default printer.

    To specify a printer, use the -P flag with lpr or the -d flag with lp, followed immediately by the name of the printer:

    % who | lpr -Pmathlw
    							

    Specifying a printer with the -P flag (or -d with lp) will always override the environment variable specified in PRINTER; therefore, you can specify the default printer with PRINTER and specify other printers as needed without any further work.

    Notice that I printed the output of the who command but received absolutely no information from the lpr command regarding what printer it was sent to, the print job number, or any other information.

    To make life easier, I'm going to redefine PRINTER:

    % setenv PRINTER mathlw
    							
  2. To find out what's in the print queue, I can use lpstat -pprinter on System V or the lpq -Pprinter command:

    % lpq -Pmathlw
    
    [email protected]:   driver not active
            Printing is disabled.
    Pos  User      Bin   Size  Jobname
    ---  ----      ----  ----  -------
      1  KOSHIHWE  0104   008  KOSHIHWE0104a
      2  KOSHIHWE  0104   008  KOSHIHWE0104b
      3  KOSHIHWE  0104   008  KOSHIHWE0104c
      4  kleimanj  0317   032  kleimanj0317a
      5  zeta      0042   008  zeta0042a
      6  jharger   0167   008  jharger0167a
      7  jharger   0167   008  jharger0167b
      8  ssinfo    0353   000  ssinfo0353a
      9  fuelling  0216   024  fuelling0216a
     10  zeta      0042   152  zeta0042b
     11  tkjared   0142   012  tkjared0142a
     12  SUJATHA   0043   016  SUJATHA0043a
     13  SUJATHA   0043   024  SUJATHA0043b
     14  SUJATHA   0043   044  SUJATHA0043c
     15  bee       0785   012  bee0785a
     16  bee       0785   056  bee0785b
     17  bee       0785   028  bee0785c
     18  ssinfo    0353   004  ssinfo0353b
     19  ssinfo    0353   000  ssinfo0353c
     20  ssinfo    0353   000  ssinfo0353d
     21  ssinfo    0353   004  ssinfo0353e
     22  stacysm2  0321   000  stacysm20321a
     23  ssinfo    0353   000  ssinfo0353f
     24  taylor    0889   000  taylor0889a
    
    mathlw: waiting to be transmitted to server.utech.edu
    
    The queue is empty.
    

    Quite a few print jobs are waiting to be sent, but it's not obvious why the printer is disabled. The output of the lpq and lpstat commands are explained in detail later in this hour.

  3. To print the file dickens.note in landscape mode, without a header page, indented eight spaces, and in reverse order, I can use the following flags:

    % lpr -hiLR < dickens.note
    							

    If I did this often, a C shell alias could be helpful:

    % alias lpr 'lpr -hiLR'
    							

    On a System V machine, you also could create the alias alias lpr 'lp', though none of these particular options is available with lp.

    If you find yourself printing to a couple of different printers quite often, you easily can define a few shell aliases to create printer-specific print commands:

    % alias mathprint   'lpr -Pmathlw'
    % alias libprint    'lpr -Plibrary'
    % alias edprint     'lpr -Pedlw'
    							

    On System V machines, the name would be this:

    % alias mathprint   'lp -dmathlw'
    % alias libprint    'lp -dlibrary'
    % alias edprint     'lp -dedlw'
    							
  4. Some systems have a command lpinfo that also offers information about printers:

    % lpinfo mathlw
    mathlw: server.utech.edu; MATH 734; multiple Apple LaserWriter IINT
    

    To find out more information about the printer, you can specify the -v flag:

    % lpinfo -v mathlw
    mathlw description:
            driver: /usr/local/lib/lp/lpmq
            printer control group: cc
            graphic filter: /usr/local/bin/psplot
            log file: /usr/spool/lpr/mathlw/logfile
            lock file: /usr/spool/lpr/mathlw/lock
            hardware line: /dev/null
            maximum job count per user = 25
            subqueue list: mathlw1,mathlw2,mathlw3
            maximum print file blocks = 3000
            make unique via bin change
            network driver: /usr/local/lib/lp/lpnc
            ditroff filter: /usr/local/lib/devps/devps
            print formats: graphics, ditroff, use pr, troff
            queue ordering: age
            host attachment: server.utech.edu
            spooling directory: /usr/spool/lpr/mathlw
            location: MATH 734
            description: multiple Apple LaserWriter IINT
    
  5. The lpinfo command also can show you a list of what printers are available, but I find the output format considerably more difficult to understand than lpstat:

    % lpinfo -a | head -15
    aglw:   server.utech.edu; AG 23; multiple Apple LaserWriter IINT
    aglw1:        server.utech.edu; AG 23; Apple LaserWriter IINT
    aglw2:        server.utech.edu; AG 23; Apple LaserWriter IINT
    aglw3:        server.utech.edu; AG 23; Apple LaserWriter IINT
    aglw4:        server.utech.edu; AG 23; Apple LaserWriter IINT
    alpslw: sentinel.utech.edu; LIB 111; Apple LaserWriter IINTX
    bio:    ace.utech.edu; COM B117; DataPrinter (self-service)
    cary:   franklin.utech.edu; CQuad (NE-B7); IBM 4019 Laser Printer
    cslw: server.utech.edu; CS 2249; Apple LaserWriter IIg
    cs115lw:     expert.utech.edu; CS 115; IBM 4019 LaserPrinter (for CS180)
    cs115lw2:    expert.utech.edu; CS 115; IBM 4019 LaserPrinter (for CS180)
    csg40lw:     franklin.utech.edu; CS G040; IBM 4019 LaserPrinter
    csg50lw:     franklin.utech.edu; CS G050; IBM 4019 LaserPrinter
    cslp1: expert.utech.edu; CS G73; C.Itoh, white paper (self-service)
    eng130ci:    age.utech.edu; ENG 130; C.Itoh, white paper (self-service)
    Broken pipe
    

    If you find this output readable, you're undoubtedly becoming a real UNIX expert!

The output of the printers command specifies the location of the printer that printed the file. I need to go to another building to pick up my hard copy. (The location is specified in the output of the printers command.)


Task 17.3: Formatting Print Jobs with pr

The printout I generated looked good, but boring. I would like to have a running header on each page that specifies the name of the file and the page number. I'd also like to have a bit more control over some other formatting characteristics. This is exactly where the pr command comes in handy. Not intended just for printing, pr is a general pagination and formatting command that can be used to display information on the screen. Even better, pr is available on both BSD and System V UNIX.


The pr program is loaded with options, most of which are quite useful at times. For example, -2 makes the output two columns, which is useful for printing results of the who command in landscape mode. The most useful options are presented in Table 17.3.

Table 17.3. Useful Flags in pr
Flag Meaning
-n Produce n-column output per page.
+n Begin printing on the nth page.
-f Don't print the page header and footer information.
-hhdr Use hdr as the head of each page.
-wn Set the page width to n characters (for landscape mode).
-m Print all files at once, one per column.

  1. My printout of the who command showed me that my choice of paper was poor. In a 128-character-wide landscape printout, I actually was using only the first 30 characters or so of each line. Instead, I can use pr to print in two-column mode:

    % who | pr -2 | more
    
    
    Dec  9 13:48 1993   Page 1
    
    
    root     console Dec 6 18:02    ab       ttypk  Dec 9 07:57  (nova)
    princess ttyaV   Dec 9 13:44    dutch    ttypl  Dec 8 13:36  (dov)
    tempus   ttyaW   Dec 9 13:43    malman   ttypm  Dec 9 13:07  (dov)
    enatsuex ttyaY   Dec 9 13:41    bakasmg  ttypq  Dec 9 13:09  (age)
    coxt     ttyaZ   Dec 9 13:35    dodsondt ttyps  Dec 8 11:37  (age)
    scfarley ttyAa   Dec 9 13:36    md       ttypv  Dec 8 08:23  (kraft)
    nancy    ttyAb   Dec 9 13:12    rothenba ttypw  Dec 9 13:15  (trinetra)
    rick     ttyAc   Dec 9 13:12    xuxiufan ttypy  Dec 9 13:16  (ector)
    fitzte   ttyAd   Dec 9 13:47    nashrm   ttyq3  Dec 9 13:04  (pc115)
    maluong  ttyAe   Dec 9 13:46    dls      ttyq5  Dec 9 13:06  (dialup01)
    af5      ttyAg   Dec 9 09:12    myounce  ttyq8  Dec 9 02:14  (limbo)
    zjin     ttyAh   Dec 9 13:44    liyan    ttyq9  Dec 9 13:11  (volt)
    herbert1 ttyAi   Dec 9 13:29    daffnelr ttyqA  Dec 9 13:36  (localhost)
    ebranson ttyAj   Dec 9 13:44    mm       ttyqB  Dec 9 10:32  (mm)
    billiam  ttyAk   Dec 9 13:36    jlapham  ttyqC  Dec 9 12:46  (mac18)
    linet2   ttyAm   Dec 9 11:04    chuicc   ttyqE  Dec 9 13:38  (icarus)
    --More-- _
    

    Notice that the pr program not only made this a two-column listing, but also added a page header that indicates the current date and page number.

On some UNIX systems, the -f flag to pr causes the program to put form feeds at the bottom of each printed page. To suppress the header and footer, use -t.


  1. The header still doesn't contain any information about the command name, which is what would really be helpful. Fortunately, I easily can add the header information I want by using pr:

    % who | pr -h "(output of the who command)" -2 | more
    
    
    Dec  9 13:50 1993  (output of the who command) Page 1
    
    
    root     console Dec 6 18:02    ab       ttypk   Dec 9 07:57  (nova)
    princess ttyaV   Dec 9 13:44    dutch    ttypl   Dec 8 13:36  (dov)
    tempus   ttyaW   Dec 9 13:43    malman   ttypm   Dec 9 13:07  (dov)
    enatsuex ttyaY   Dec 9 13:41    bakasmg  ttypq   Dec 9 13:09  (age)
    coxt     ttyaZ   Dec 9 13:35    dodsondt ttyps   Dec 8 11:37  (age)
    scfarley ttyAa   Dec 9 13:36    md       ttypv   Dec 8 08:23  (kraft)
    nancy    ttyAb   Dec 9 13:12    rothenba ttypw   Dec 9 13:15  (trinetra)
    rick     ttyAc   Dec 9 13:12    xuxiufan ttypy   Dec 9 13:16  (ector)
    fitzte   ttyAd   Dec 9 13:47    dls      ttyq5   Dec 9 13:06  (dialup01)
    maluong  ttyAe   Dec 9 13:46    myounce  ttyq8   Dec 9 02:14  (limbo)
    maritanj ttyAf   Dec 9 13:49    liyan    ttyq9   Dec 9 13:11  (volt)
    af5      ttyAg   Dec 9 09:12    daffnelr ttyqA   Dec 9 13:36  (localhost)
    zjin     ttyAh   Dec 9 13:48    mm       ttyqB   Dec 9 10:32  (mm)
    herbert1 ttyAi   Dec 9 13:29    jlapham  ttyqC   Dec 9 12:46  (mac18)
    ebranson ttyAj   Dec 9 13:44    chuicc   ttyqE   Dec 9 13:38  (icarus)
    --More-- _
    

    That's much better.

  2. I might want to compare the contents of two different directories. Remember that the -1 flag to ls forces the ls program to list the output one filename per line, so I can create a couple of files in this format easily:

    % ls -1 src > src.listing
    % ls -1 /tmp > tmp.listing
    							

    These files look like this:

    % head src.listing tmp.listing
    ==> src.listing <==
    calc-help
    calc.c
    fixit.c
    info.c
    info.o
    
    
    ==> tmp.listing <==
    Erik/
    GIri/
    Garry/
    MmIsAlive
    Re01759
    Re13201
    Sting/
    VR001187
    VR002540
    VR002678
    

    Now I will use pr to build a two-column output:

    % pr -m src.listing tmp.listing | head -15
    Dec  9 13:53 1993   Page 1
    
    
    calc-help                           Erik/
    calc.c                              GIri/
    fixit.c                             Garry/
    info.c                              MmIsAlive
    info.o                              Re01759
    massage.c                           Re13201
                                        Sting/
                                        VR001187
                                        VR002540
    Broken pipe
    
  3. This would be more helpful if I could turn off the blank lines automatically included at the top of each listing page, which is a job for the -f flag (or -t, if your version of pr is -f for form feeds):

    % ^pr^pr -f
    pr -f -m src.listing tmp.listing | head -15
    Dec  9 13:56 1993   Page 1
    
    
    calc-help                           Erik/
    calc.c                              GIri/
    fixit.c                             Garry/
    info.c                              MmIsAlive
    info.o                              Re01759
    massage.c                           Re13201
                                        Sting/
                                        VR001187
                                        VR002540
                                        VR002678
                                        VR002982
                                        VR004477
    Broken pipe
    
  4. It looks good. Now it's time to print by piping the output of the pr command to the lpr command:

    % !pr | lpr
    pr -f -m src.listing tmp.listing | head -15 | lpr
    

The pr command can be used to ensure that your printouts are always clean and readable. Again, it's a perfect place to create an alias: alias print 'pr | lpr' or alias print 'pr | lp'. Even without any flags, pr automatically adds page numbers to the top of each page.


Task 17.4: Working with the Print Queue

On a personal computer, you might be used to having your printer directly connected to your system, so anything you print using PRT: (on DOS) or File | Print (on Windows and the Mac) instantly prints. Unfortunately, UNIX doesn't grant you the luxury of using your own personal printer. Instead, it handles print requests in a print queue, a managed list of files to print. When you send a file to a printer with lpr or lp, the request is added to a queue of files waiting to print. Your request goes to the bottom of the list, and any subsequent print requests are added below yours. Your print request gradually moves up to the top of the list and prints, without interrupting the print requests of those folks ahead of you.


Sometimes it can be frustrating to wait for a printout. However, there are some advantages to using a queuing system over simply allowing users to share a single printer. The greatest is that you can use the lprm command to change your mind and remove print requests from the queue before they waste paper. The lprm command works with the print job name, which you can learn by checking the print queue using lpq. Both lprm and lpq can either use the default PRINTER setting or can have printers specified with -Pprinter. The lpq command also can limit output to just your jobs by adding your account name to the command.

If your system doesn't have lprm, use the cancel command to remove entries from the print queue. The lpstat command is also the System V replacement for the lpq command, though many sites alias lpq = lpstat to make life a bit easier.

To use cancel, you need to specify the name of the printer and the job ID, as shown in the lpstat output. If I had print request ID 37 on printer hardcopy, I could cancel the print request with the command cancel hardcopy -37.

  1. A glance at the mathlw queue shows that a lot of files are waiting to print:

    % lpq
    
    [email protected]:   driver not active
            Printing is disabled.
    
    Pos  User      Bin   Size  Jobname
    ---  ----      ----  ----  -------
      1  KOSHIHWE  0104   008  KOSHIHWE0104a
      2  KOSHIHWE  0104   008  KOSHIHWE0104b
      3  KOSHIHWE  0104   008  KOSHIHWE0104c
      4  kleimanj  0317   032  kleimanj0317a
      5  zeta      0042   008  zeta0042a
      6  jharger   0167   008  jharger0167a
      7  jharger   0167   008  jharger0167b
      8  ssinfo    0353   000  ssinfo0353a
      9  fuelling  0216   024  fuelling0216a
     10  zeta      0042   152  zeta0042b
     11  tkjared   0142   012  tkjared0142a
     12  SUJATHA   0043   016  SUJATHA0043a
     13  SUJATHA   0043   024  SUJATHA0043b
     14  SUJATHA   0043   044  SUJATHA0043c
     15  bee       0785   012  bee0785a
     16  bee       0785   056  bee0785b
     17  bee       0785   028  bee0785c
     18  info      0353   004  info0353b
     19  info      0353   000  info0353c
     20  info      0353   000  info0353d
     21  info      0353   004  info0353e
     22  stacysm2  0321   000  stacysm20321a
     23  info      0353   000  info0353f
     24  taylor    0889   000  taylor0889a
    
    mathlw: waiting to be transmitted to server.utech.edu
    
    The queue is empty.
    

    My print job is job number 24, with the print job name taylor0889a. Figure 17.1 explains the different fields in the queue listing.

    Figure 17.1. The lpq output format explained.

    The printer is also turned off. You can see at the top of the lpq output the telltale message driver not active, printing is disabled. Obviously, if the printer is disabled, it's rather futile to wait for a printout.

  2. To limit the output to just those print jobs that are mine, I specify my account name:

    % lpq taylor
    [email protected]:   driver not active
            Printing is disabled.
    
    Pos  User      Bin   Size  Jobname
    ---  ----      ----  ----  -------
      1  taylor    0889   004  taylor0889a
    
    mathlw: waiting to be transmitted to server.utech.edu
    
    The queue is empty.
    
  3. To check the status of another printer, I can specify the printer with the -P flag:

    % lpq -Pb280il
    
    [email protected]:      driver not active
    
    The queue is empty.
    
    b280il:     waiting to be transmitted to franklin.utech.edu
    
    The queue is empty.
    

    That's better. The queue is empty.

  4. To remove my print job from the mathlw print queue, I simply specify the print job name from the lpq output:

    % lprm taylor0889a
    							

    UNIX carries out my command without giving me confirmation that it has done so, but a quick check with lpq shows me what's up:

    % lpq taylor 
    [email protected]:   driver not active
            Printing is disabled.
    
    The queue is empty.
    
    mathlw: waiting to be transmitted to server.utech.edu
    
    The queue is empty.
    

I wish that the default for the lpq command would show only print jobs that I have in the queue, and I could use the -a flag to show all print jobs queued. Furthermore, instead of incorrectly saying The queue is empty, lpq should report something more useful, such as there are 23 other print jobs in the queue.


  1. Now I resubmit the print job request, this time to the b280il printer:

    % !pr -Pb280il
    pr -f -m src.listing tmp.listing | head -15 | lpr -Pb280il
    

    Uh oh! I don't want that head -15 cutting off the information in the printout.

    % lpq -Pb280il
    [email protected]:      driver active; no job printing
    
    Pos  User      Bin   Size  Jobname
    ---  ----      ----  ----  -------
      1  nfsuser   0058   268  nfsuser0058a
      2  nfsuser   0054   012  nfsuser0054a
      3  taylor    0889   000  taylor0889a
    
    b280il:     waiting to be transmitted to franklin.utech.edu
    
    The queue is empty.
    

    To remove my print request, I use lprm:

    % lprm taylor0889a
    "taylor0889a" not located.
    

    I've made a second mistake! I need to specify the printer:

    % lprm -Pb280il taylor0889a
    							

    Now I can fix the original command and print the files correctly:

    % pr -f -m src.listing tmp.listing | lpr -Pb280il
    							

UNIX offers some printing capabilities you might not be accustomed to working with, particularly the capability to change your mind and stop a print job before it touches paper. You can see that it's a good idea to set the PRINTER environment variable to your favorite printer so that you can save yourself from struggling to enter weird printer names each time you print a file.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.142.146