Skip Navigation
Site HomeSearch

On-Line Reference:
RedHat Linux Unleashed

Did this help?
... or
Donate at PayPal®...

Tux the Pengin

OK, here's a freebie: A simulation of the old text-based Star Trek game we used to play on HP 2100's using a Teletype ASR-33 as a console: StarTrek Game

Setting Up To Print With LPR, and Share the Printer


  1. References
  2. Printer Setup Procedure
  3. Should Be Good-To-Go: Let's Print
  4. Troubleshooting
  5. New for RedHat 8 and up
  6. Some Useful LPR Server Commands


Printer Setup Procedure

I have an HP Deskjet 855C and this procedure got me going to the point that I can use "lpr" to print text and graphic files, even Netscape pages and screenshots. of course with later distributions, CUPS printing is much prefered for more powerful machines -- my laptop is under powered and lpr is just fine for that.

  1. I logged in as root (hence, the "#" signs).
  2. I created a new /etc/printcap file:
  3. # printcap by rik nilsson 4Oct99
    lp|hpps|HP Deskjet 850 for postscript, using gs for rasterization:
  4. I created an error log file.
    # touch /var/log/lpd-errs
  5. I made a soft link from the printer port (<tt>/dev/ttyS1 on a PowerPC G3 - don‚?ā¨∆ň?t use the old /dev/cua1) to the printer device, /dev/hpdj, and enabled group rights on the port:
    # ln -s /dev/ttyS1 /dev/hpdj
    # chmod o+g /dev/ttyS1
  6. I created and modified the /usr/local/bin/hpps input filter file as defined in the next-to-last line of the /etc/printcap file:(note: I added the "-i 3" in line 6 to indent 3 chars for 3-hole punching.)
    # You must change values for your variables
    # and directories, as appropriate for your printer.
    my( $cmd ) = "| /usr/bin/enscript -M Letterdj -i 3" .
                 "  --pass-through --lineprinter -o - |"  .
                 " /usr/bin/gs -q -dNOPAUSE  sDEVICE=deskjet" .
                 " -sOutputFile=- - ";
    my( $linespeed, $stty_opts, $device) =
    # if you are using a parallel cable, use the line below
    #  (57600, "raw -echo -crtscts ixoff ixon", "/dev/hpdj");
    # if you are using a serial cable, comment out the line above
    # and use this line instead:
       (57600, "raw -echo crtscts -ixoff -ixon", "/dev/hpdj");
    # Configure printer‚?ā¨∆ň?s serial port
    system ("stty $linespeed $stty_opts < $device ");
    # Pipe input to this script to a command for generating
    # appropriate output for our printer ("man perlipc" for details)
    open (SCRIPTED,$cmd) || die "Can‚?ā¨∆ň?t script?!";
    # Catch any signals wrt breaking pipes (naughty naughty)
    local $SIG{PIPE} = sub { die "Scripter pipe broke" };
    # Let‚?ā¨∆ň?er rip...
    while (<STDIN>){
       print SCRIPTED $_;
    close SCRIPTED || die "Can‚?ā¨∆ň?t close temporary pipe.";
    exit 0;

    The lines I had to modify were the ones defining the location of the enscript and gs files. Use "find / -name enscript" and "find / -name gs" to locate them in your installation.

  7. I made this file an executable one using:
    # chmod 755 /usr/local/bin/hpps
  8. I enabled the printer queue with
    # /usr/sbin/lpc enable hpps

Should Be Good-To-Go: Let‚?ā¨∆?ĄĘs Print Something

Print something from the commandline:

$ lpr "This will print on your printer."

Print a file, with a margin of 5 characters width:

$ pr -o 5 somefile.txt | lpr


That should get you going; if not,
check the permissions on all the files mentioned in this tip, look at the last lines of the /var/log/lpd-errs file (<tt># tail -f /var/log/lpd-errs &) to get an idea where your losing it. Check the /var/spool/lpd directory for stray files - there should only be printer (lp, lp0, etc.) directories and a "lock.lpd" file in there. If "cfxxxxx" and "dfxxxxx" and "lock" files appear, you‚?ā¨∆ň?re trying to print to a non-existant printer, I think - something‚?ā¨∆ň?s wrong. If all else fails, I once restored printing by doing this: "cd /var/spool/lpd; chown -R root.root *", which gives root access to all the files and directories in /var/spool/lpd.
Prints strange characters, multiple pages, lpd quits
You forgot to "# chmod o+g /dev/ttyS1", so your script can‚?ā¨∆ň?t set the serial port parameters. Do a "# ls -l /dev|grep ttyS1". The group for /dev/ttyS1 should be "lp", the permissions should be "rw-rw----"
Won‚?ā¨∆ň?t print at all
Try "# cat /etc/printcap > /dev/hpdj"; if that works, then check the /var/log/lpd-errs file for hints - maybe there is a syntax error in your script, /usr/local/bin/hpps, or your /etc/printcap is not formatted correctly, or "lp" is missing from the printer name of "lp|hpps|hp".

Sharing Your Printer

The Network

For review, here is the network as we have it so far. For the purposes of this tip, the server (host) PC is known as "xku", which has a class C local IP address of

Figure 1, The Home Network

Remote: In each remote computer (one of the workstations) you first create a remote printer specification using

# printtool

Figure 2, creating a remote printer specification with "printtool" on a workstation

When printtool opens, click "Add" and fill in the blanks. Our entries are shown in Figure 2.

Printer names: The printer name appears in your server‚?ā¨∆ň?s /etc/printcap file, along with the "spool directory. Issue the command

# less /etc/printcap

on the server PC and review the /etc/printcap file to find out how the printer is set up on your server. If you have not previously set it up for local printing, see the internet HOWTOs or my tips on how to do that. Note: we also specified "lp" as a name in printtool because that was Netscape‚?ā¨∆ň?s default.

# Please do not edit this file directly unless you know what you are doing!      
# Be warned that the control-panel printtool requires a very strict format!     
# Look at the printcap(5) man page for more info.                               
# This file can be edited with the printtool in the control-panel.              
##PRINTTOOL3## LOCAL uniprint NAxNA letter {} U_CanonBJC610 bjc610a0 1          

New - For RedHat 8 and up:

RedHat 8.0 implements the LPRng print system (along with CUPS). Use printtool as above (it looks new and different, but works the same). To enable the print server to accept print requests from remote hosts (client PCs on your network) do the following, as root:

  1. Create or edit the file /etc/hosts.lpd and add names or IPs of the client hosts you wish to have access to the file.
  2. Edit the file /etc/lpd.perms and locate the line:
  3. Just above that line, add
  4. Now, restart the print daemon with the command:
    service lpd restart

Some useful lpr server commands:

lpq          # displays the current jobs in the lpr queue
lprm -a      # removes all current jobs in the lpr queue
Print plain