-->
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 its 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, youre 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 isnt useful at all because a very small amount of spooled PostScript data can generate a large number of output pages.
You may want to add a line to your login scriptor even to the default user login scriptthat 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.
The following shell script is a very simple input filterit 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 printers 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:
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.)
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
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
cd /usr/spool/lpd/myprinter chmod ug=rwx,o=rx input_filter
See Starting vi by Using an Existing File, p. 183
ls -l | lpr -Pmyprinter
See Viewing the Contents of a File, p. 325
TROUBLESHOOTING:
I get a message saying lpd: connect: No such file or directory. The printer daemon /etc/lpd isnt running. You may have forgotten to add it to your /etc/rc.local file. Or maybe you did add it but you havent 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 havent created the spool directory specified in the printcap entry, or youve 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 dont come out, make sure that any input filter youve specified is present in the correct directory and has the correct permissions. If youre 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 youre 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 youll feel silly if this is the cause), make sure that your input filter actually generates output and that the output device isnt /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 doesnt 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 youve 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 |