Question & Answer
Question
Capturing a Spool File in AIX
Answer
This document describes several ways to capture and see files as they pass through the AIX spool system. This information applies to AIX Versions 4 and later.
In problem determination, it is often useful to look at the file being printed through different states of the print process. There are a number of options for capturing a spool file in AIX depending on the reason for capturing data. Here are four basic methods:
- Create a file in /dev/ and make a print queue to a file. This is useful to see the data after it has gone through the backend.
- Print to a disabled queue and use the command lpstat -t to find the location of the file. This is useful to see the file before it goes to the queue backend.
- Use iptrace to trace the file as it goes to a network print server or printer.
- Use a custom backend. This gives the option to write a program that archives the data to a specific file.
Capturing a file as it enters the queue
Capturing print file sent over the network
Use a custom backend
Printing to a file in the /dev/ directory
By adding a print queue that prints to a file, it is able to see exactly how the virtual printer modifies the file being printed. The commands sent to the printer can be analyzed and compared with the commands expected based on the printers technical reference manual. By combining this with the second method, "Capturing the file as it enters the queue", one can see exactly what is added by a particular virtual printer and the effect of qprt print flags and virtual printer customization.Procedure
-
Create the file in /dev/lpx. Enter the following sequence of commands:
cat /dev/null > /dev/capture chgrp printq /dev/capture chmod 777 /dev/capture
-
To create the queue, do the following:
- Enter smit mkpq.
-
Choose:
File File (in /dev directory)
- Choose the manufacturer of the selected printer.
-
Choose the printer model.
Name of existing FILE in /dev directory capture
- Enter queue names for various emulations and press Enter or DO.
-
Print to the file. Enter:
- echo "AAAAA" | qprt -Pqueue_name (This is easy to find in the capture file.)
- qprt -P<queue> <filename>
- View the results and complete the following steps:
- Enter cat -v /dev/capture.
- To see the results, enter vi /dev/capture.
- To identify control characters, enter od -ca /dev/capture.
- To rezero the capture file, enter:
cat /dev/null > /dev/capture'
- echo "AAAAA" | qprt -Pqueue_name (This is easy to find in the capture file.)
Capturing a file as it enters the queue
Capturing a file as it enters a queue is useful in at least two circumstances.- Sometimes the problems resulting from improper formatting are created by the application. To see exactly what is in the application, disable the queue and capture the spool file.
- When printing from a client to an AIX host, the print flags sent by the client may cause problems on AIX. To make sure the problem is not with the file, capture the spool file and print it locally.
Procedure
-
Create any queue as described in step one or disable an existing queue.
For example, we will call the queue capture.
-
Disable the queue. Enter:
disable capture
-
Print to the queue.
-
Check the queue status to see that the job has printed. Enter:
lpstat -t -vcapture
Do not leave a space between v and capture. The -t flag causes the file to be displayed.Queue Dev Status Job Files &nb sp; User ------- ----- --------- --- ------------------ ---------- capture captu DOWN QUEUED 147 STDIN.23330 jwtesch@aixnts &n bsp; 03/05/97 09:21:04 1 15 2 1 & nbsp; &n bsp; /var/spool/lpd/dfA692aixnts
- If users are printing remotely, then the actual file will be in /var/spool/lpd, probably starting with dfA. If the file was printed on the local system, then it will either be the original file name, or a file in /var/spool/qdaemon.
-
Examine the file. Complete the following steps.
- Enter cat -v /var/spool/lpd/dfA003sun10.
- Enter cp /var/spool/lpd/dfA8d5aix4prt /tmp/capture.file.
- To print the job to the ps queue and to see if the file will print locally, enter qprt -Pps /tmp/capture.file.
- To look for control characters, like form feeds, in the file enter od -ac /var/spool/lpd/dfA692aixnts.
- To compare this against the file after it goes through the virtual printer enter, diff /var/spool/lpd/dfA692aixnts /dev/capture.
-
Look at the flags in the job description file.
The processing of a job that has been sent to an AIX queue is affected
by the flags that have been used in the printing process. Because all of
the print commands in AIX call the enq print program, it can
sometimes be surprising what enq flags are generated by the different
commands. For example, issuing the print command lpr calls enq
with a -c flag and a -Ban. This means that the file is copied
to /var/spool/qdaemon before being printed and that it will have
a header page.
To see the job description file, follow these steps:
- Enter cd /var/spool/lpd/qdir to change into the directory that contains the job description file for all jobs that are queued.
- To show which jobs are currently queued, enter ls -l . The file name contains the user ID and the queue so you can identify the file for your job.
- Enter pg <file_name> and look for flags as shown below.
Sample flags:
enq valid flags are on one line:
NAME=joebob-Pps-Ttitle
qprt flags all start with $#@!:
$#@!-d $#@!-p $#@!-z $#@!+
-
Remove the job from the queue.
Nothing will be sent to /dev/capture.
- Enter cancel ### where ### is the job name.
- cancel 363
- Enter cancel capture to remove all files from the queue.
- Enter cancel ### where ### is the job name.
Capturing print file sent over the network
Remote printing jobs in AIX can be captured with the iptrace utility. This is discussed in more detail in the technical document Tracing Remote Printing. This document contains only a brief outline of how to look at the print job itself as it passes over the network. Tracing the data that passes over the network may help determine where problems occurred when the output on the printer is different than what was expected. The steps to capturing remote print jobs are:- Start iptrace running with the following command:
iptrace -p printer -a -b -s <source_host> -d <dest_host> /tmp/trace.out
- -p printer (use the word printer) or 515 says look at port 515 only. This will not get logon traffic. If you are tracing the printer HP JetDirect, use port 9100, 9101, or 9102 depending on the port. For other socket programs, replace the word printer with the TCP/IP port number.
- -a suppresses ARP packets.
- -i en0 interface. Use only if multiple network cards are in the system.
- -b changes the -d and -s to bidirectional mode. Get data in both directions.
- -s indicates the source host name or IP address where the print command is issued.
- -d indicates the destination host name or IP address where the printer is located.
- /tmp/trace.out. This can be any file name. It will be created with 11 bytes and then will get filled with data. It is a binary file that must later be formatted with ipreport.
- Now print to the queue. Enter:
enq -Pqueue_name <filename>
Print the job to the remote queue or use lpstat -v<queue_name> if you want to trace the status report. - Check the size of the trace file. Enter:
ls -l /tmp/trace.out
Check if the file has grown. If it is still 11 bytes, then the command has been issued incorrectly. Kill the process and retry. - Find the process ID of the iptrace command. Enter:
ps -ef | grep ipt
- Get the process ID from the output and kill this process. Enter:
kill -9 <process_id>
- Format the trace data to create a text file you can view and print. Enter:
ipreport /tmp/trace.out > /tmp/report.out
- To see the data only, you can now grep the report with four zeros.
Enter:
grep 0000 /tmp/report.out
This will show all the data that passes over the network in both hexadecimal and ASCII text, allowing you to compare with the starting file, as well as what printed on the remote printer.
Use a custom backend
-
A simple backend can be used to look at flags and at the file.
- Start the script with #!/bin/ksh.
- To find out what flag was sent, enter echo "Parms are: $*" > /tmp/flags.
- To see how many arguments are passed, enter echo "Args = *#" >> /tmp/flags'.
- To save the file if only one argument was passed to the queue, enter cat $1 > /tmp/filename. Use $2 for 2 arguments and so on.
- Give the script executable permissions and put it in the printq group.
- Enter smitty mkpq.
- Select Other ----- User Defined Backend
- Name of QUEUE to add: ----- qname
- Name of QUEUE DEVICE to add: ----- qnamed
- BACKEND PROGRAM pathname: ----- /usr/lbin/myback.sh
This gives the option to write a program that archives the data to a specific file. Some hints while developing this script are to use a shell script with commands like:
When adding the script backend, add the queue as follows:
Historical Number
isg1pTechnote0400
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
isg3T1000257