Print Management

The printer subsystem includes spoolers, real printers, virtual printers, backends, and queues. A printer can be attached directly to a local system, or a print job can be sent over a network to a remote system.

How it Works

SMIT can be used to set up the printer. SMIT allows the printer device to be created, the virtual printer to be added and customized, and the queues to be manipulated.

Although it is possible to start SMIT with the smit command to access the printing menus, the simplest way is to use smit printer. The data flow is shown in the following diagram:


Figure: Data Flow of a Print Job

The printing command places the file, plus any print flags, onto the queue. When the printer is ready, the qdaemon passes the file and flags to the printer backend which formats the output for the specific printer. The data is then passed to the printer device driver which communicates with the actual device and prints the file.

It is also possible to bypass the queue and backend by redirecting the file to the device (with the cat command).

AIX uses the virtual printer concept which allows more control over each printer, and more customization. The following section describes the new terminology to enable the rest of this chapter to be understood.

The following diagram demonstrates some of the possible combinations of queues that can be configured in AIX on the RISC System/6000.


Figure: Possible Combinations of Queues

Printing Commands

There are four commands which use the piobe that can be used to print the files. The four commands are lp, lpr (UNIX commands), and qprt, enq (AIX commands). These commands ignore some of the splp settings (splp command allows to change or to display printer driver settings), since they use the settings that are contained in the virtual printer. The virtual printer settings can be configured using SMIT .

The commands lp, lpr and qprt are actually just a front end to the enq command. Therefore, the first thing that happens to a printed file is that it is passed to the enq program. The enq program simply places the information about the file, along with the flags, in the queue for the qdaemon to deal with. The queue is actually the /var/spool/qdaemon directory.

If the job is not a file (for example the output of a command piped to enq), then a real file is created in /var/spool/qdaemon which contains the data to be printed. The information in the /var/spool/lpd/qdir file then points to the file in /var/spool/qdaemon.

Spooling versus Queueing

The significant difference is illustrated after a print job is submitted:

The AIX queueing system supports the lp, lpr, enq and qprt commands.

When you work with a local printer you can use these commands:

When you work with a remote printer the print files are always saved in a temporary location: the directory /var/spool/lpd/qdir.

Qdaemon Program

Qdaemon generally starts with the startsrc command when the system is powered on. startsrc is a command to the srcmstr daemon which is started from /etc/inittab.

The qdaemon keeps track of the print requests in the /var/spool/lpd/qdir directory and ensures that the jobs are sent to the proper printer at the proper time. It also keeps track of the status of the printers and stores printer usage data for system accounting purposes. This information is held in the /var/spool/lpd/stat directory.

If the qdaemon is stopped it will be restarted by the srcmstr command.


**** NOTE: **** Never kill the srcmstr process as it controls other daemons that will be running on the system.

To stop the qdaemon issue the following command:

# enq -G
This is the preferred method of taking the qdaemon down gracefully. If there are no jobs queued, then the qdaemon may be stopped with the following command:
# stopsrc -s qdaemon

Either way the qdaemon can be started again with the following command:

# startsrc -s qdaemon

Note: Always ensure that qdaemon is definitely not running before starting it as a second qdaemon will adversely affect the printing subsystem. If a second qdaemon is accidentally started then this may be stopped with the kill -9 command. This method should never be used to stop the qdaemon under normal conditions.

Printer Backend

The qdaemon runs a backend process when output is sent to a particular device. The qdaemon sends to the backend process the names of files to be printed and any specified print flags. The backend uses the printer control information supplied from the ddi files to format the data before it is sent to the device driver. This printer control information is customized with SMIT using the Change / Show Characteristics of a Virtual Printer option.

The ddi information is found in /var/spool/lpd/pio/ddi where a ddi file exists for each virtual printer that has been created. This ddi information is created when the virtual printer is added, from the information in /usr/lpd/pio/predef directory, where descriptions of all supported printers are held.

When the virtual printer is added, a relevant printer control file in the directory /usr/lpd/pio/predef is copied to the directory /var/spool/lpd/pio/custom. A digested version is also put into /var/spool/lpd/pio/ddi, which is the version that is actually used.

These copies of the file may be customized via SMIT using the Change / Show Characteristics of a Virtual Printer option. You can also use the SMIT fastpath smit chvirprt. The backend program returns data to the qdaemon via a status file in the /var/spool/lpd/stat directory. This is where the qchk -A command finds the information that it displays.


# qchk -A
queue Dev Status Job Files User PP % Blks Cp Rnk
----- --- ------ --- ------------ --- -- - ---- -- ------
lp0 lp0 READY
lp1 lp0 DOWN
QUEUED 2 /etc/motd Root 3 1 1
bsh bshde READY

The default backend process is piobe, when a printer is added using SMIT. Piobe no longer requires a string of flags in /etc/qconfig because the information is held elsewhere. The information that piobe uses is in the /var/spool/lpd/qdir directory. This information is supplied with the print command and the default files are in the /var/spool/lpd/pio/ddi directory.

For more information on piobe use man piobe to view the manual pages, or search on piobe in InfoExplorer.

The backend program must be a binary executable file. For example, a queue that processes compilation jobs might use the cc program as its backend. To use a shell script as part of a backend, the binary executable is /bin/ksh. The entry in the /etc/qconfig file should look like this:


backend = /bin/ksh /home/user/bin/scriptname

This will execute a shell as a backend. That is the script shell /home/user/bin/scriptname will be executed in the korn shell environment.

Note: You may choose to directly set a shell script as the backend. In this case, you must insert a magic number line at the top of the script shell. It may be this line, if your script has to be run in the korn shell environment:

#!/bin/ksh

Remote Printer Backend

TCP/IP allows remote printing from one machine on the network to another. This is achieved by a combination of the TCP/IP daemons and a remote printer backend in the /etc/qconfig file. The client and server can be configured through SMIT using the Manage Remote Printer Subsystem option of the smit printer menu.

The remote printer backend, that is the rembak program, allows the users of the client system to access printers on a remote system. This is particularly useful if there are specific types of printers that are only available from one system but are required by users of another.

The remote printing setup of AIX V3 is described in detail in the publication Printing for Fun and Profit Under AIX V3 and an example is described in Remote Printer Example.

splp Command

In AIX the splp command is used for changing the device driver characteristics of both parallel and serial printers.

If a printer device is defined but not allocated to any queue, then the only way to access the device is to redirect it with the following command:

# cat /etc/motd > /dev/lp0

In this instance splp is available to allow members of the system group to change some characteristics of the device driver and any user may view them. The splp output for a printer will appear as follows:


# splp
device = /dev/lp0 (+ yes ! no)
CURRENT FORMATTING PARAMETERS (ignored by qprt, lpr, and lp commands)
Note: -p + causes the other formatting parameters to be ignored.
-p + pass-through? -c + send carriage returns?
-l 66 page length (lines) -n + send line feeds?
-w 132 page width (columns) -r + cr after lf?
-i 0 indentation (columns) -t + suppress tab expansion?
-W ! wrap long lines? -b + send backspaces?
-C ! convert to upper case? -f + send form feeds?
CURRENT ERROR PROCESSING PARAMETERS
-T 60 timeout value (seconds) -e ! return on error?
CURRENT SERIAL INTERFACE PARAMETERS
-B 9600 baud rate -s 8 character size (bits)
-N ! enable parity? -S ! two stop bits?
-P ! odd parity?

Note: When the printing command is used with the piobe backend, splp is set to pass-through during printing. Therefore, some of the splp parameters set by the user are ignored.

To display the device driver characteristics of the lp0 printer issue the
splp /dev/printer command (where printer is replaced by the device for example lp0).

Parameters can be changed with the splp command in the following form:

# splp -w 132 -B 9600 lp0

Clearly the printer device name must be that of the printer that has been changed. If the /dev directory is not specified then it is assumed. The above example changes the width to 132 and the baud rate to 9600, until the next reboot or the next splp command. The default printer is lp0.

More information about splp can be found using man splp or searching for splp in InfoExplorer.

Printing Components

To setup a printer you start by issuing the fastpath command for SMIT by typing: smit printer. This will present three options:

This area of SMIT contains all of the options and tools necessary to setup and configure printers. There are two basic steps to adding a printer:

All details about these functions in SMIT are provided in InfoExplorer and an example is described in Local Printer Example and Remote Printer Example.

AIX Printing Commands

The first thing that appears to be different when printing on AIX V3 is that the print command echoes the filename to the standard output. This is because the print command is actually a built-in korn shell command that allows display of the value of a string and has nothing to do with printing.


# print myfile
myfile

There are a number of printing commands in AIX from various sources. qprt and enq are from IBM, lp is from AT&T and lpr is from BSD**. This section is provided to describe the ways in which the qprt, qcan, qadm, enq and qchk commands work.

Note: Not all of the options described below are available for every printer. In this case an error message will be returned.

Information about lp, lpr, lpstat, lpq, cancel and lprm can be found using the man command or searching in InfoExplorer.

qprt Command

This is the preferred command for printing on AIX. This command can be run through SMIT by typing smit qprt. Following is a list of examples:

enq Command

The enq program is a general purpose program that accepts requests for printing, cancel requests, alters the priority of a job and displays the status of print queues and print devices. The enq command is used to print files to specified queues.

# enq filename
This causes the file called filename to be submitted to the default queue, usually called lp0 (the first stanza in the /etc/qconfig file; the easiest way to check is to enter enq -q which will display the status of the default queue). There are several flags associated with the enq command and are entered in the following form:
# enq -flag filename

For more information see the enq command under InfoExplorer.

qchk Command

Options are: -A (all), -L (long form), -# jobnumber, -P queue, -q default queue, -u username, -w seconds (displays status every number of seconds).

Here are some examples:

Job Control Commands

Some of these following commands require root authority:

Note: There is no command to cancel jobs from the remote host. In this case, the way to cancel a job is to use these preceding commands on the local host with a telnet, rexec or rsh command.

Summary of Configuration Commands for Printers

There are clearly many commands in AIX V3 and there is often a choice of commands to do the same job. The following figure describes some of the common tasks and suggests some commands that may be used.


Figure: Summary of Printer Commands

The above commands may be executed from the command line or through SMIT. Remember that details of these commands can be found using the man command or searching for the command in InfoExplorer.

Associated Files

The flow of the AIX queuing system is shown in Figure - Flow of the AIX Version 3 Queueing System.


Figure: Flow of the AIX Version 3 Queueing System

  1. Commands are used to submit jobs to the queueing system (enq, qprt, lpr, lp). Although not shown, the enq command also checks the /etc/qconfig file to determine if queue names are valid.
  2. Once the command submits the print job, the /etc/qdaemon is notified and takes control of managing the print job.
  3. The print queue/device information is obtained by the qdaemon from the /etc/qconfig file.
  4. The qdaemon updates the status file for the destination printer and puts a filename specifying the queue in /var/spool/lpd/qdir.
  5. When the queued job reaches the top of the queue the qdaemon passes the file (data stream) to the backend program. Some backends are responsible for passing the file (data stream) to the virtual printer.
  6. The virtual printer contains information on the printer control sequences to switch fonts, paper bins, lines per page, and so on. The virtual printer passes this information back to the backend.
  7. The backend passes the filtered data stream from the virtual printer to the printer. The device is both the soft device and the physical printer.

This diagram also shows a status file /var/spool/lpd/stat and the directory where job request information is temporarily stored .

The files below are most of the files that are used by the printing subsystem. These files are generally manipulated by the commands or by SMIT. Therefore it is rarely necessary to edit them.

The following list describes the purpose of these files and directories.

/etc/qconfig
An ASCII file. Actually /usr/lpd/qconfig file is linked to this file. It has the queue and queue device stanzas in it. Ensure the link with /usr/lpd/qconfig doesn't break. SMIT and the commands actually edit /usr/lpd/qconfig.
/etc/hosts.lpd
This file contains the names of any machines that are authorized to use this machine as a print server.
/etc/inittab
This file contains some of the programs that should be run at bootup. It contains lines to start the lpd and qdaemon daemons.

Note: These daemons are started with startsrc which is a part of the srcmstr daemon.

/usr/lpd/aixlong
These files are the status filter files used with the remote printing facility. The first part of the file name indicates its use. It should be noted that aixlong is for AIX Version 3 and the aixv2long is for the RT. The others are for AT&T and BSD respectively.
/usr/lpd/aixshort
/usr/lpd/aixv2long
/usr/lpd/aixv2short
/usr/lpd/attlong
/usr/lpd/attshort
/usr/lpd/bsdlong
/usr/lpd/bsdshort
/usr/lpd/digest
This file is the digester for qconfig. It converts the ASCII /usr/lpd/qconfig file into the binary /usr/lpd/qconfig.bin.
/usr/lpd/lpd
This file is the remote printer daemon. It is actually a link to /usr/sbin/lpd.
/usr/lpd/pio
Subdirectory for the printer backend commands and files.
/usr/lpd/piobe
The printer backend that processes the files that are defined to use it.
/usr/lpd/qconfig
The actual file that is processed by the qdaemon to build the qconfig.bin. This file is linked to /etc/qconfig file. If the link is removed there can be numerous errors with print facilities.
/usr/lpd/qconfig.bin
This is the digested version of the qconfig file.
/usr/lpd/qstatus
This command prints the status of the queue or queues.
/usr/lpd/rembak
This is the remote printer backend.
/usr/lpd/pio/burst
This subdirectory contains the files necessary to print the header pages for all of the supported data streams.
/usr/lpd/pio/predef
This subdirectory contains files of attributes for both supported and unsupported printers. The filenames are in two parts, the first being the printer type, the second part being the data stream type. When a virtual printer is added, one of these files will be used as a template for the customized file, which is described next.
/usr/lpd/pio/etc
This subdirectory contains most of the printer backend utility files, including pioburst, piodigest, pioformat, piofquote and pioout.
/usr/lpd/pio/fmtrs
This subdirectory contains the formatters for the different printer types. Examining the files shows that some printers do not require formatters such as PostScript printers.
/usr/lpd/pio/fonts
This subdirectory contains only a single font file for the 4201 printer to translate code page 850.
/usr/lpd/pio/trans1
This subdirectory contains the files for the stage one translation of a code page.
/usr/lpd/pio/trans2
This subdirectory contains the files for the stage two translation of a code page.
/usr/sbin/lpd
This is the remote printer daemon. /usr/lpd/lpd is linked to this file.
/var/spool/lpd/qdir
This subdirectory contains a file for each locally spooled job. Each file contains information about the file, the user and the queue to which it will be sent.
/var/spool/lpd/stat
This subdirectory contains the information on the status of the print devices. They are used by qdaemon and the printer backend to communicate the status of the print device to each other.
/var/spool/lpd/stat/numfile
This file contains the job number that is running.
/var/spool/lpd/stat/pid
This file contains the pid of the qdaemon process.
/var/spool/lpd/pio/custom
This subdirectory contains all of the defined virtual printer information. This information is the undigested version.
/var/spool/lpd/pio/ddi
This subdirectory contains all of the digested virtual printer information for each of the virtual printers that have been defined.
/var/spool/lpd/pio/dev
This subdirectory contains dummy device files for printers driven by, but not attached to, the host computer (for example printers attached to Xstations).
/var/spool/lpd/pio/flags
This subdirectory contains flags files which help keep track of loaded fonts.
/var/spool/lpd/pio/msgx.queue:queuedev
These files contain messages from the printer. These messages should be removed by the system administrator. These files will remain in the directory until they are erased. Not all the messages are registered in these files; mostly the messages that were not able to be sent or emailed to the root user, submitter or console will be sent to these files.
/var/spool/qdaemon
If the printjob is not a file (for example pipe output) a real file is created in /var/spool/qdaemon which contains data to be printed. The information in the /var/spool/lpd/qdir file points to the file in /var/spool/qdaemon. When you use the command lpr you work in spooling mode, there is a copy of your file in this directory.

Local Printer Example

We will discuss an example how to configure a local printer. First, you have to read the documentation for your printer. You may need printer-specific information, such as default values and options, to configure the printer. You must have root authority to do the following procedure.

Installation of the Local Printer

For example if you want to add a printer of the type 4202-III XL on a host for example named pippin, do the following:

Once a printer/plotter device has been created and made available, making a virtual printer through SMIT will create the queue, the queue device and the virtual printer itself. A virtual printer is a definition of what the piobe should do to format a file correctly for the attached printer. The files that are used to create the virtual printer are in /usr/lpd/pio/predef and the customized version is then copied to /var/spool/lpd/pio/custom which is digested into the /var/spool/lpd/pio/ddi directory.

The advantage of having a virtual printer is that it is now very easy to customize and change the parameters used to format the output.

This section of SMIT is different from the rest in that it prompts for answers one at a time and doesn't use the normal selection menus.

Notes: Queue names may contain numbers but the first character must be a letter.

Once a default queue has been selected, it will no longer be prompted for, if adding multiple data streams for the same printer.

Any emulation bypassed by entering a ! at the prompt can be added later using the same option. This means some emulations can be left to a later date on which the emulations that are already defined must also be bypassed with a !.

The previous commands used to create a local printer creates the queue and queue device in the /etc/qconfig file, each with the same name.

This is the contents of your /etc/qconfig file:


bsh:
device = bshdev
discipline = fcfs
bshdev:
backend = /bin/sh
lp0:
device = lp0
lp0:
file = /dev/lp0
header = never
trailer = never
access = both
backend = /usr/lib/lpd/piobe

The purpose of a queueing system is to maintain a queue of jobs that are waiting for their turn to run. Usually, the jobs print hardcopy.

Another common use for queueing is batch processing. Having users submit jobs to a batch shell can help level system load by assuring that certain types of jobs are run via a queue and thus, one at a time.

This concept could be applied to a software development shop where a great deal of compiling goes on. In this case, a shell is used as the backend program and the first stanza of /etc/qconfig file bsh stanza is used.

Print Job on a Local Printer

Now we can check the status of the printer with the command qchk.

Note: For some commands in this preceding example root authority is required.

Remote Printer Example

Remote printing allows a user on one machine to use a printer on a network attached machine as if it were a local printer. This is a feature of the AIX Printing Subsystem and TCP/IP.

Remote printing is issued from the client system and is transferred by the Remote Printing Backend to the network where it is picked up by the server system and printed.

Installation of a Remote Printer

The server is for example the host named pippin and the client is the host named bruce.

Print Job on a Remote System

Queueing System Problems: Clearing your Queueing System

When the queueing system shows one or more queues in DEV_WAIT, when qdaemon repeatedly dies, or when your queueing subsystem is completely down, you can use the following method to clear and restart the queueing system. If you find that this procedure must be constantly run to keep your queueing system in working order, you may have a more serious problem with your configuration. Work with your local support team to resolve this situation.

To clear the queueing system, you will need to stop the qdaemon process and check that the /var file system is not full. Then, clear the directories and start the qdaemon process again.

  1. Log in as root.
  2. Let current print jobs finish printing or cancel them. To list current print job numbers, enter:
    # lpstat
    

    To cancel print jobs, enter:

    # enq -x <job number>
    
  3. Stop the qdaemon process by entering:
    # stopsrc -s qdaemon
    
  4. Use the following command to ensure that qdaemon has not forked other processes and left them running:
    # ps -eaf | grep qdaemon
    # ps -eaf | grep pio
    

    Only one line of output should be displayed for each of the above commands (the two grep commands, in fact). If this is the case, skip to step 6.

    If there was more than one line of output, note the process ID (second column of output) for each process except "grep qdaemon" and "grep pio" (process names are in the last column).

  5. Kill the forked processes with the following command:
    # kill -9 <process ID>
    

    Run the command for each process ID you noted above, replacing
    <process ID> with the process ID.

  6. If it is important to save the current print jobs from being deleted, continue with this step. If not, go to step 7.

    If your print job exists in one of the following directories, make a copy of it and place it in /tmp; you can print it when the queueing system is running again (in these directories, the files will have unfamiliar system names): /var/spool/qdaemon
    /var/spool/lpd

  7. If the /var file system gets too full, you may experience problems with qdaemon or the spooler. Large print jobs may fail, or 00root files with zero length may appear in your qdir directory. Rebooting the system may not help clear files out or restart qdaemon.

    Enter the df command and look in the %used column for /var to see if the file system is too full. Free or increase space in the file system as necessary.

  8. Change directory:
    # cd /var/spool/lpd/qdir
    
  9. Issue the pwd command to verify that you are in the proper directory (qdir); then remove all files in this directory:
    # rm *
    
  10. Change directory again:
    # cd /var/spool/lpd/stat
    
  11. Issue the pwd command to verify that you are in the proper directory (stat); then remove all files in this directory:
    # rm *
    
  12. Change directory:
    # cd /var/spool/qdaemon
    
  13. Issue the pwd command to verify that you are in the proper directory (qdaemon); then remove all files in this directory:
    # rm *
    

    Continue with the following steps if you are having trouble with remote queues or with lpd. Otherwise, skip to Step 16.

  14. Change directory:
    # cd /var/spool/lpd
    
  15. Issue the pwd command to verify that you are in the proper directory (lpd); then remove all files in this directory:
    # rm *
    
    (This will not remove the subdirectories, so you will see normal error messages).
  16. Now, start qdaemon:
    # startsrc -s qdaemon
    

    The queueing system should start normally. If some queues are still down, try to bring them up with enable <qname> command.

Explanation of Queue Statuses

The list of the different statuses that a queue can have follows. This describes when the status occurs and possible recovery methods:

Queue Status

Remote Queue Status