/usr/spool/mlp/controlsThe file /usr/spool/mlp/controls is the data base for the print spooler lp. The superuser root can modify this file, either with a text editor or (to a more limited extent) with the command lpadmin.
The format of controls is simple. Every blank line is ignored. All text after the pound sign `#' is also ignored; you can use this feature to embed comments in the file. The rest of the file consists of commands, each of which has the format _c_o_m_m_a_n_d==_a_r_g_u_m_e_n_t_s.
The following describes the commands that you can embed in controls:
printer = linenlq, /dev/lpt2, pannlq
printer = linepr, /dev/lpt2, linepr
printer=disk,/dev/null,disk
For example, consider the command
printer = linenlq, /dev/lpt2, pannlq
This command names a printer linenlq, declares that it is plugged into port /dev/lpq2, and requests that lpsched massage input to the printer through script /usr/spool/mlp/backend/pannlq. When lpsched processes a request that is directed to printer linelq, it pipes the text of the job into script pannlq, and redirects the output of pannlq to device /dev/lpt2.
It is important to remember that a printer-control script is not restricted to a few commands that the spooler understands. Each is a true shell script that can use any or all COHERENT commands to process text. The limits of what a script can do are set only by your imagination.
Consider the following examples. In the discussion, above, of the command printer, two scripts were mentioned: pannlq and linepr. Both send their output to the same physical printer, but they process the input text in different ways. The following gives the contents of linepr:
# filter the input through pr
pr
# throw a page at the end
echo "\f\c"
This script filters its input through the COHERENT command pr, which paginates the text and puts a header on it. It then echoes a formfeed character, to force the printer to throw a blank page at the end of the job. As in other shell scripts, a pound sign `#' introduces a comment and blank lines are ignored.
The following gives the contents of script pannlq:
# turn on near-letter-quality printing
echo "\021\033n"
pr
# turn off near-letter-quality printing
echo "\021\033P"
This script resembles the first, except that it includes commands to echo the magic strings that turn on and turn off near-letter-quality printing on this printer. This is one small example of the flexibility you can employ in devising a script
As with other shell scripts, you can modify the behavior of a printer-control script by setting environmental variables. For example, consider the following variation on the script linepr:
if [ $HEADER ]; then
pr -h "$HEADER"
else
pr
fi
# throw a page at the end
echo "\f\c"
If you have exported the environmental variable HEADER, then this script prints it at the top of each page; otherwise, it prints the default header. You can use the same technique to do other work, such as force the printing of a banner page.
The lp spooler reserves for its own use the environmental variables MLP_COPIES, MLP_FORMLEN, MLP_LIFE, MLP_PRIORITY, MLP_SPOOL. Your scripts can also use these variables. For more information on what each does, see its entry in the Lexicon.
When lpsched uses a printer-control script, it passes it three arguments: respectively, the sequence number of the print job (which identifies the job uniquely); the name of the user; and the number of copies being printed. You can use this information to control the printing of output; for example, consider the following:
for i in `from 1 to $3`
do
pr -h "User $2 - Copy $i of $3"
done
echo "\f\c"
Note, too, that just as each physical printer can be accessed in different ways via different scripts, so too the same script can be used by multiple physical printers. If you had multiple Panasonic printers plugged into your system, you could use the above script with each of them to massage their input appropriately.
One last example. As noted above, the output of a printer- control script can be directed to any device, not just a port. (It can also be redirected to non-existent ports, so be careful when you enter your pprriinntt commands.) You can use this feature to redirect formatted text into files or other interesting places. Consider the following printer command:
printer=disk,/dev/null,disk
This creates a ``printer'' named disk. The text filtered through file disk is redirected to /dev/null. The contents of script disk show what this device is up to:
tee /tmp/D$$
This script uses the COHERENT command tee to redirect its input both to the standard output (which in the case of printer disk is thrown away) and into a file in directory tmp. You can use this command to save input for further examination later.
This discussion just scratches the surface of what you can do with the lp print spooler and its control scripts. For more information, see the Lexicon entries for printer and lp.