-->
Previous Table of Contents Next


The rm and rp Fields

Sending your print data to a printer attached to another machine is as simple as specifying the remote machine rm and the remote printer rp and making sure that the print device field lp is empty.


NOTE:  Data is still spooled locally before it’s transferred to the remote machine. Any input filters you specify are also run.

The sh and sf Fields

Unless you have a lot of different people using your printer, you’re most likely not interested in banner pages, so specify sh.

Suppressing form feeds, by specifying sf, is most useful if your printer is typically used for output from word-processing packages. Most word-processing packages create complete pages of data, so if the printer daemon is adding a form feed to the end of each job, you get a blank page after each job. If the printer is usually used for program or directory listings, however, having that form feed ensures that the final page is completely ejected, so each listing starts at the top of a new page.

The mx Field

The mx field allows you to limit the size of the print data to be spooled. The number you specify is in BUFSIZE blocks (1KB under Linux). If you specify zero, the limit is removed, allowing print jobs to be limited only by available disk space.


NOTE:  The limit is on the size of the spooled data, not the amount of data sent to the physical printer.

If a user tries to exceed this limit, the file is truncated. The user sees a message saying this:


(lpr: file-name: copy file is too large)

For non-PostScript printers, this limit is useful if you have users or programs that may deliberately or accidentally create excessively large output. For PostScript printers, the limit isn’t useful at all because a very small amount of spooled PostScript data can generate a large number of output pages.

Setting the PRINTER Environment Variable

You may want to add a line to your login script—or even to the default user login script—that sets up a PRINTER environment variable. Under the bash shell, a suitable line is export PRINTER=myprinter. This prevents people from having to specify -Pmyprinter every time they submit a print job.

To add more printers, just repeat this process with different printer names. Remember that you can have multiple printcap entries, all using the same physical device. This way, you can treat the same device differently, depending on what you call it when you submit a print job to it.

Creating a Test printcap Entry

The following shell script is a very simple input filter—it simply concatenates its input onto the end of a file in /tmp after an appropriate banner. Specify this filter in the printcap entry and specify /dev/null as the print device. The print device is never actually used, but you have to set it to something; otherwise, the printer daemon complains.


#!/bin/sh

# This file should be placed in the printer’s spool directory and

# named input_filter. It should be owned by root, group daemon, and

# be world executable (-rwxr-xr-x).

echo ------------------------------------------------ >> /tmp/

date                                                  >> /tmp/

echo ------------------------------------------------ >> /tmp/

cat                                                   >> /tmp/

In the following printcap entry, notice the reasonably readable format and the use of the continuation character (\) on all but the last line:


myprinter|myprinter: \

:lp=/dev/null: \

:sd=/usr/spool/lpd/myprinter: \

:lf=/usr/spool/lpd/myprinter/errs: \

:if=/usr/spool/lpd/myprinter/input_filter: \

:mx#0: \

:sh: \

:sf:

Putting It All Together

To put all the preceding bits together, the following steps guide you through setting up a single printer on /dev/lp0. You can then extend this to other printers. (You have to be root to do all this, by the way.)

1.  Check the permissions and locations of lpr, lprm, lpc, lpq, and lpd. Earlier in this chapter, Table 20.2 listed the correct settings and directories.
2.  Create the spool directory for your printer (named myprinter for now). Make sure that both the directory and printer are owned by root, belong to the daemon group, and have write permissions for user and group and read-only permission for others (-rwxrwxr-x). Use the following commands:

   mkdir /usr/spool/lpd

   mkdir /usr/spool/lpd/myprinter

   chown root.daemon /usr/spool/lpd /usr/spool/lpd/myprinter

   chmod ug=rwx,o=rx /usr/spool/lpd /usr/spool/lpd/myprinter

3.  In the /usr/spool/lpd/myprinter directory, create the necessary files and give them the correct permissions and owner. Use the following commands:

   cd /usr/spool/lpd/myprinter

   touch .seq errs status lock

   chown root.daemon .seq errs status lock

   chmod ug=rw,o=r .seq errs status lock

4.  Create the shell script input_filter in the /usr/spool/lpd/myprinter directory. Use the input filter given earlier in the section “Creating a Test printcap Entry” for your filter. Make sure that the file is owned by root, belongs to the daemon group, and is executable by anyone. Use the following commands:

   cd /usr/spool/lpd/myprinter

   chmod ug=rwx,o=rx input_filter

5.  Create the /etc/printcap file if it doesn’t already exist. Remove all entries in it and add the test printcap entry given in the “Creating a Test printcap Entry” section. Make sure that the file is owned by root and is read-only to everyone else. You can use the chmod command to set the proper file permissions: -rw-r- - r- - (or 644 in octal).
6.  Edit the rc.local file (you can use any ASCII editor, such as vi or emacs). Add the line /etc/lpd to the end to run the printer daemon each time the system boots. It’s not necessary to boot now, however; just run it by hand with the lpd command.


See “Starting vi by Using an Existing File,” p. 183
7.  Do a test print by entering the following:

   ls -l | lpr -Pmyprinter

8.  Use the ls command to look in /tmp for a file named testlp.out. It should contain your directory listing, which you can check with the more, less, or cat command. See Chapter 17, “Managing Files and Directories,” for more information on these commands.


See “Viewing the Contents of a File,” p. 325
9.  Use an ASCII editor such as vi to make the following edits to /etc/printcap:
  In the first printer entry, change both occurrences of myprinter to testlp only in the first line.
  In the second entry, change /dev/null to your real print device—for example, /dev/lp0.
  In the second entry, remove the if line completely.

Now, copy the myprinter entry so that you have two identical entries in the file.
10.  Either reboot the system or kill the printer daemon and restart it. You do this because the printer daemon looks only at the /etc/printcap file when it first starts up.
11.  Run a test print again using the command ls -l | lpr -Pmyprinter. This one should come out on your physical printer.


TROUBLESHOOTING:  
I get a message saying lpd: connect: No such file or directory. The printer daemon /etc/lpd isn’t running. You may have forgotten to add it to your /etc/rc.local file. Or maybe you did add it but you haven’t booted since then. Add it and reboot, or just run /etc/lpd. Remember that you have to be root to do this.

I get a message saying Job queued, but cannot start daemon. This often appears right after the lpd: connect message; same problem as the preceding.

I get a message saying lpd: cannot create spooldir/.seq. You haven’t created the spool directory specified in the printcap entry, or you’ve misnamed it. An alternative (though much less likely) answer is that you have too little disk space left.

I get a message saying lpr: Printer queue is disabled. As root, use lpc enable printer-name to enable the printer. Note that as root, you can submit jobs even to a disabled printer.

I submit a print job and there are no error messages, but nothing comes out on the physical printer. There could be many reasons:

  Make sure that the physical printer is switched on, selected, and physically connected to the device specified in the /etc/printcap file.
  Use the lpq command to see whether the entry is in the queue. If it is, the device may be busy, the printer may be down, or there may be an error on the printer. If there are errors, check the error log specified in the printcap entry for clues.
  You can use the lpc status command to check whether the printer is down, and you can use lpc up printer-name or lpc restart printer-name to bring it back up if it is (you need to be root to do this).

If, after checking, your print jobs still don’t come out, make sure that any input filter you’ve specified is present in the correct directory and has the correct permissions. If you’re running syslogd, you can look in your logs for messages from lpd. If you see log entries saying cannot execv name of input filter, this is almost certainly the problem.

Another possibility is that your printer is a PostScript printer and you’re not sending PostScript to it. Most PostScript printers ignore non-PostScript data. You may need to install an appropriate text-to-PostScript input filter.

Last (and you’ll feel silly if this is the cause), make sure that your input filter actually generates output and that the output device isn’t /dev/null.

My printer seems to have locked up. None of the preceding techniques seems to solve the problem. When all else fails in the case of a nonprinting printer, the next-to-last resort is to kill the lpd daemon and restart it. If that doesn’t work, the last resort is to reboot your Linux system with the shutdown -r now command. Make sure that no one else is logged in and that you’ve saved any files before using the now option; otherwise, specify a time and also give a message to your other users before shutting down the system. You also can test the printer on a DOS or Windows machine to make sure that the physical device itself is working.



Previous Table of Contents Next