Question & Answer
Question
AIX System V Printing - Interface Scripts: Lab3
Answer
This document applies to AIX 5.3 and later when using the System V print subsystem.
- Overview of interface scripts
- Creating the printer with the hpnpIS model
- Testing the printer and interface script
- Set the default paper size to letter
- Examine the interface script
- Optional: Change the script to use a PCL header
- Summary
Overview of interface scripts
In System V printing, the interface script functions as the backend program does in AIX qdaemon based printing. The interface script is called by lpsched when a file is ready to print. The flags are passed to the interface script by lpsched. There are five default flags, and then a series of other flags that are specific to a particular printer model script. The interface script also controls which program is called to send the output to the physical printer. This means that any printer setup must be done by the interface script. The interface script is a shell script that resides in the /etc/lp/interfaces directory which is also linked so that it appears as /var/spool/lp/admins/lp/interfaces. There is a separate script for each defined printer, and the name of the script is the same as the name of the printer.The standard and PS interface models which are used by default provide very little printer setup capability. This means that by default you have no ability to select the paper size, orientation, or tray from the command line.
In this lab you will start with this model and customize it to print to a local file by changing the internal filter used to send the output to the printer.
Creating the printer with the hpnpIS model
To use an alternate model script when creating a printer, use the -i flag to point to the model. To use the hpnpIS.model script use -i /usr/lib/hpnp/hpnpIS.model.
The -v flag is used to specify the output device. When creating a local file, this would normally point to the printer device file in /dev (e.g. -v /dev/lp24). For this lab you can create the printer to send the output to a file instead, so that you can see the effects of changes made without using paper or having a specific printer attached.
Create the printer with these steps:
# touch /dev/custom
# chown lp /dev/custom
# chmod 600 /dev/custom
# lpadmin -p cust1 -v /dev/custom -i /usr/lib/hpnp/hpnpIS.model \
-I simple -T unknown
Use the type simple because then the scheduler
will not call filters. Do this so that the interface script can
call them as needed.
Before you use the accept and enable commands, make
some changes to the script so it will output to the file that
is specified as stdout by the scheduler when the interface
script is called.
The interface file that is called is now /etc/lp/interfaces/cust1. There are two things that must be changed to get this to work the way that we want it to.
- The NETWORK parameter must be changed to cat or any other
filter that will send the data to the desired printer. This line will
look like this:
NETWORK="/usr/lib/lp/bin/lp.cat"
- The NETWORK be default is directed to the LOGFILE. We need
to let it be directed to stdout.
) | $NETWORK 2>> $LOGFILE 2>&1 to ) | $NETWORK 2>> $LOGFILE
Once you have made these two changes you can print.
Enable the printer to accept jobs.
# accept cust1 # enable cust1
Testing the printer and interface script
Use the following steps to send data through the printer and script.# lptest 5 5 | lp -d cust1 # cat /dev/custom
Let's briefly look at the print output file. It contains the following sections:
- A PostScript banner page
- A series of PCL setup commands. (Note that the escape
character will show up as ^[)
^[%-12345X^[%-12345X@PJL enter language=pcl ^[)0B^[&k2G^[&l26A^[&l0O^[&l66F^[&l7.27C^[(8U^[(s12H^[)s12H^[&a5L^[&l1H^[&l1S
- The printed data file
!"#$% "#$%& #$%&' $%&'( %&'()
- A series of PCL reset commands
^[)0B^[&k2G^[%-12345X^[%-12345X@PJL enter language=pcl ^[&k2G^[&l1T^[%-12345X
The setup commands for the printer are as follows:
| Escape sequence | Description |
|---|---|
| Esc%-12345X@PJL enter language=pcl | Enter PCL mode |
| Esc)0B | Specify Secondary Symbol Set |
| Esc&k2G | Tell the printer to add carriage returns to line feeds |
| Esc&l26A | A4 paper (The default is not good for US) |
| Esc&l0O | Portrait orientation |
| Esc&l66F | 66 lines per page |
| Esc&l7.27C | 7.27 VMI (distance for a line feed) |
| Esc&(8U | Roman 8 character set |
| Esc(s12H | Pitch of 12 cpi |
| Esc&a5L | Left column is 5 spaces |
| Esc&l1H | Select paper source |
| Esc&l1S | Duplex, Long-Edge Binding |
Set the default paper size to letter
Edit the /etc/lp/interfaces/cust1 file and go down to the paper selection part of the file. This begins with
case "$pagemode" in
legal)
echo "\033&l3A\c"
;;
Note that the default is designated just before the esac statement by:
*)
echo "\033&l26A\c"
;;
To change the default paper size to letter change
this line to: (Escape ampersand small-L two A slash small-c)
as shown here.
echo "\033&l2A\c"
While you are still in the file, find where pagemode is set, and what
lp -o flags you would expect to work.
If you look at the file closely, you will see that the options are parsed in a for loop starting with:
for option in $options
do
case "$option" in
so|showopts)
# Set debug flag to show options.
showopts="yes"
;;
In this case, you could use a "-o so" or "-o showopts" from the lp
command
line to match the case statement.
Farther down this loop you will find the statements that set the pagemode such as:
letter)
# letter size paper
pagemode="letter"
;;
legal)
# legal size paper
pagemode="legal"
;;
ledger)
# ledger size paper
pagemode="ledger"
;;
This indicates we can select these paper sizes with lp as follows:
$ lp -o letter ... $ lp -o legal ... $ lp -o ledger ...Next test to see if this is really true. First save the changes to the file and then use these commands.
# > /dev/custom (clear the print file destination) # echo "AAAA" | lp -d cust1 # more /dev/customNotice the setup command line now shows
^[)0B^[&k2G^[&l2A^[&l0O^[&l66F^[&l7.27C^[(8U^[(s12H^[)s12H^[&a5L^[&l1H^[& l1SAAAAThe letter command is now Esc&l2A as you set the default.
Now try the option -o ledger.
# > /dev/custom (clear the print file destination) # echo "AAAA" | lp -d cust1 -o ledger # more /dev/customThe paper size command now shows ^[&l6A. Based on this you could easily add a new paper size command by adding commands to the two loops.
Examine the interface script
Because you are printing to a file, and the stdout is set to that file, you can use echo commands to output debug information to this print destination. Edit the cust1 interface script and add some echo statements to help us better understand what is going on. The five standard options that are always sent to the interface script by the lpsched deamon are shown here.Search the file for Set standard variables and you will see:
# Set standard variables based on arguments passed in. # reqid=$1 user=$2 title=$3 copies=$4 options="$5" shift; shift; shift; shift; shift files="$*"
This is a good place to look at what is going on. After the line that sets the files variable add these echo statements:
echo "Request id is $reqid" echo "User is $user" echo "Title is $title" echo "copies is $copies" echo "options are $options" echo "File to print is $files" echo "Output command is $NETWORK" # Look at the user environment env echo echo "Continue"
Now clear the print destination file, and print using the -o flag as you did earlier to set the paper size. Then use the more command to look at the /dev/custom file. Following is sample output:
Request id is cust1-41 User is aix4prt!root Title is copies is 1 options are ledger flist=':5' File to print is /var/spool/lp/tmp/aix4prt/41-1 Output command is /usr/lib/lp/bin/lp.cat _=/bin/env LANG=C ... USER=root ... NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat Continue
You may notice that this comes before the header page.
Optional: Change the script to use the PCL header
The routine PCL_banner is commented out, and replace by
PCL_banner () {
PS_banner
}
See if you can change the functional PCL banner.
Summary
During this lab you have learned how to:- Create a printer with a custom interface script
- Change the default paper size in the interface script
- Learn how the -o flag interacts with the interface options
- Use the echo statement in the script for debugging.
- Optional: Change the banner function
Similar labs include:
- AIX System V Printing - lpr/lpd remote printing: Lab 4
- AIX System V Printing - System V filters: Lab 2 (Section titled "Adding a filter to an interface script")
Historical Number
isg1pTechnote0775
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
isg3T1000457