TOC PREV NEXT INDEX
View/print PDF file
UNIX at Fermilab

Chapter Contents

Chapter 11: Printing
  11.1 The Fermilab Print Server FNPRT
  11.2 The Print Commands
    11.2.1 The flpr Command
    11.2.2 Setting the Environment Variables
  11.3 Printer Nicknames
  11.4 Pre-Printing Options
    11.4.1 Convert ASCII to PostScript: a2ps
    11.4.2 Print Multiple Pages per Sheet: psnup
    11.4.3 Set Duplex Mode
  11.5 Other Print Utilities


Chapter 11: Printing


This chapter covers the standard Fermilab UNIX print utility flpr, as well as filter programs and techniques available for formatting the output prior to printing. flpr is the Fermi implementation of the standard UNIX lpr utility. Most software applications supplied by the Computing Division use flpr as a default.

Note that many X-windows applications allow you to specify in a pop-up window the print command you want to use.

11.1 The Fermilab Print Server FNPRT

From centrally-supported UNIX machines at Fermilab, flpr print requests are routed through the Fermilab print server FNPRT.FNAL.GOV. FNPRT provides access to a large number of supported printers on-site.

To get a full list of printer queues supported by FNPRT, run the command obtain printer to create the file flp.printers in your current directory. Or check http://fnprt.fnal.gov:631/printers.

11.2 The Print Commands

The Fermilab print utility flpr (pronounced "flipper") implements the lpd printing protocol, and can be used to print UNIX files to any print server using this protocol, which includes most UNIX systems. Related commands are flpq (to check the print queue) and flpk (to kill a submitted print job; not supported universally). The format of each command is:

% flpr [<options>] [<file>] ... 
% flpq [<options>] [<users>|<jobs>] ... 
% flpk [<options>] [<users>|<jobs>] ... 

The options are described in the man pages. All three programs display a list of their options when given an argument of -\?. Only the options supported by the lpd host (the print host) function, however.

11.2.1 The flpr Command

The following command produces the version of flpr in use, when and where it was created, the flpr defaults in effect, and the command format:

% flpr -\? -v 

To print a file, the flpr command format is:

% flpr [-q <queue>] [-h <print_host>] [-l <login_name>] <file> 

-q Option

If the -q option is not specified, the queue is taken from (in order of precedence):

  1. environment variable FLPQ
  2. user control file (.flprrc)
  3. system control file(s)
  4. data compiled into flpr

-h Option

If the -h option is not specified, the default print host is taken as FNPRT.FNAL.GOV. For this to work, the print queue must be known to FNPRT (most are). You can set your own default printer host with the environment variable FLPHOST, or put an appropriate entry in your .flprrc user control file.

-l (lowercase L) Option

Another option for the flpr command that may occasionally be useful is -l <login-name>. This specifies the remote login name to be used in case you want another user name associated with the print job. The default name is the same as that on the current system.

11.2.2 Setting the Environment Variables

You can set environment variables such as FLPQUE and FLPHOST with the setenv command for the C shell family (see section 9.5 Shell Variables and Environment Variables):

% setenv FLPQUE <queue> 
% setenv FLPHOST <host> 

and for the Bourne shell family:

$ FLPQUE=<queue>; export FLPQUE 
$ FLPHOST=<host>; export FLPHOST 

11.3 Printer Nicknames

A useful feature of flpr is the capacity to use nicknames. A nickname specifies the printer host computer and the queue as a pair. If you often use a printer unknown to FNPRT, this feature may be handy for you. You would then enter a print command in this format:

% flpr -P <nickname> <file> 

The flp.printers file mentioned in section 11.1 The Fermilab Print Server FNPRT defines many nicknames, most or all of which are associated with the host FNPRT, and is therefore more useful as a queue reference for the -q option. An example nickname is wh10w_lw, which is defined as:

printer wh10w_lw fnprt.fnal.gov wh10w_lw

Why are printer nicknames useful? If you're using a printer not recognized by the flpr defaults, you'll need to specify both host and queue unless you use a nickname. Also, we recommend that you use nicknames rather than queue names in shell scripts. If a printer fails or is removed, then its associated nickname can be redefined, and the scripts don't need to be changed. If a queue name is specified in a shell script, then this capacity does not exist. You can define a nickname yourself, or if a widely-used printer is down, it may be appropriate for your system administrator to establish a substitute printer by changing the nickname in flp.printers.

A printer nickname does not have to be the same as the printer queue name. It may be a short, easily remembered name, such as ps for a postscript printer or lp for a text printer. Such personal printer nicknames can be established in your personal flpr control file, $HOME/.flprrc.

As an example .flprrc, assume you use the FNPRT queues b0trwqms_hp for text printing, and b0trwqms_ps for Adobe PostPscript printing. You want to use the nicknames lp for text printing and ps for PostScript. Further, you would like the print jobname to contain identifiers for your login name and the file being printed. You could build a .flprrc as follows1:
host fnprt.fnal.gov 
queue b0trwqms_ps 
identifier %l$%b 
printer ps fnprt.fnal.gov b0trwqms_ps 
printer lp fnprt.fnal.gov b0trwqms_hp 

If this file exists, it will be used automatically. flpr also accesses any system-wide defaults files, such as flp.defaults and flp.printers stored in a system directory. The flp.defaults file contains default values for the host, username, printer queue, protocol temporary filename format and one or more associations between a nickname and a host and printer queue pair.

11.4 Pre-Printing Options

a2ps and psnup, described below, are in the UPS product psutils. You may need to run setup psutils before using them. They can be used from the UNIX command line as well as from many applications. pr is also available to format the pages before printing with flpr. pr is explained in the man pages.

a2ps and psnup are described in detail in the man pages and in the Fermilab DCD Release Note 41.0 Users Guide to UNIX Printing Utilities.

11.4.1 Convert ASCII to PostScript: a2ps

The a2ps utility converts ASCII to two-column PostScript by default, and encloses the text in boxes with headers indicating date, time, filename and page number. You also get a line saying "Printed by <username> from <node>". You can override the defaults; see the man pages.

a2ps is useful if the printer can only accept PostScript. You can use it to produce different output formats (e.g., "2-up", where two pages of your file are shrunk to fit on a single sheet). It provides options to add items like line numbers, user, file, and system information to the output. The command syntax is:

% a2ps [<global options>] <files> [<positional options>] <files> 

where <global options> apply to all files being printed, and <positional options> are applied only to the files found in the remainder of the command line (with the exception of -H as noted in the man page which only applies to the next file).

Here is an example where we pipe the output of a2ps to flpr (-p indicates portrait mode):

% a2ps -p <file1> | flpr -q wh10w_lw 

11.4.2 Print Multiple Pages per Sheet: psnup

The psnup utility takes a PostScript file and prints it "<n>-up". This refers to how many pages get printed on a single sheet. Portrait and landscape mode alternate as <n> changes. Occasionally this procedure doesn't work due to problems with PostScript variance.2 The syntax of the command is:

% psnup [-p<n>] [-r] [-R] [-s<n>] <files> 

where:

-p<n>
the number of pages of PostScript (or spots) that should be printed per sheet of paper. <n> is constrained to be 2, 4, 8, 16, 32, or 64.
-r
sets the first spot in lower right and progresses horizontally to the upper left. This is handy for when the pages have already been reversed by another program, and you are printing on a printer that reverses pages.
-R
sets the first spot in the upper left hand corner and progresses horizontally to the lower right. This is for non-reversing printers.
-s<n>
<n> is the number of the spot you want the first page of output to be placed. The first spot on the page is 0, not 1.

11.4.3 Set Duplex Mode

Duplex mode refers to printing on both sides of the paper. This is often desirable for larger documents, and most printers support this feature.

PostScript Files

To print a PostScript file in duplex mode on a printer that supports this feature, you must prepend some specific text to the file. An easy way to do this is to maintain this text in a separate file, and concatenate it to your PostScript file when you are ready to print it in duplex mode. The two-line text file, which we'll call duplexps here, must have the following contents:
%! 
statusdict begin true setduplexmode end 

To print your PostScript file in duplex mode, enter the command:

% cat duplexps <postscript_file> | flpr -q<duplex_printer> 

Text Files

For text files, you need to prepend a different sequence to the file. The technique we present here works with any PCL-based printer with a duplex device in it (assuming no filters are in the way) . Since text files are easy to edit, just add the following line to the top of your file3:
<ESC>&l1S<ESC>&a0G 

The trick is to get the escape character in your file! The sequence <Ctrl-[> will work for escape, but it must be preceded by a "quoting" character, which differs from editor to editor.

For this (these) editor(s):
... enter:
vi
<Ctrl-v> <Ctrl-[>
emacs
<Ctrl-q> <Ctrl-[>
NEdit
Use Insert Control Character from the Edit menu; escape is 27 decimal. The escape character may not echo on your screen depending on your font.

... to insert an escape character. Then print the file in the usual manner to an appropriate printer.

11.5 Other Print Utilities

There are two other traditional printing systems under UNIX. One of these is lpr, upon which flpr is based. lpr requires that each printer be defined in the local /etc/printcap file, which must be done by the system administrator. One of flpr's advantages is that no such definition is required since the host name and print queue can be specified on the command line. lpr is the default print command used by some applications, however. You can obtain in your current directory the file printcap which contains all printcap entries for print queues defined on FNPRT by executing the command:

% obtain printcap 

The other traditional printing system is called lp. This has its own set of files which must be set up by system administrators and is recommended for use only in situations where the other options are not available to you.

1
The identifier in the file is equivalent to the -I option described in the flpr man page.

2
psnup inserts PostScript code in front of the PostScript it is given. Because PostScript is a programming language, this doesn't always work. The file may be printed in its original format, it may never be printed, or it may print fine!

3
After the first ampersand (&), the characters are: lower case L (l), one (1), uppercase S (S). The character before the final G is a zero (0).


TOC PREV NEXT INDEX
View/print PDF file
CRL Product Home Page | CRL Manual Home Page | Computing Division | Fermilab at Work | Fermilab Home
This page generated on: 06/27/03 17:08:54