Linux printing/Queues

From Ever changing code
Jump to navigation Jump to search

Print Queues commands

LPD - linux print demon runs Linux Print system
LPR - linux print command, you need to be root to use it, sends prints to symbolic_link /dev/lp that links to physical_printer
LPRM - cancel print jobs
LPC - controls the lpd program

Print directly to printer (root)

cat thesis.txt > /dev/lp 

For the purpose of security, only the root user and users in the same group as the print daemon are able to write directly to the printer. This is why commands such as lpr, lprm, and lpq have to be used to access the printer.

LPR - Print (users)

When lpr is executed, it first copies the specified file to a certain directory (the spool directory) where the file remains until lpd prints it. Once lpd is told that there is a file to print, it will spawn a copy of itself (what we programmers call forking). This copy will print our file while the original copy waits for more requests. This allows for multiple jobs to be queued at once.

$ lpr [ options ] [ filename ... ]   #if file is not specified STIN will be sent to print_spooler
$ cat thesis.txt | lpr
$ pr -l60 thesis.txt | lpr      #pr prepares a file to be printed

The lpr command-line arguments:

Pprinter -specifies the printer to use
h -suppresses printing of the burst page
s -creates a symbolic link instead of copying the file to the spool directory (useful for large files)
#num -specifies the number of copies to print

The example below creates a symbolic link to the file thesis.txt in the spool directory for the printer named dj, where it would be processed by lpd. It would then print a second copy of thesis.txt.

$ lpr -#2 -sP dj thesis.txt  

LPQ - viewing the print queue

$ lpq  # returns the contents of the default printer's queue
lp is ready and printing
Rank   Owner      Job  Files                            Total Size
active mwf        31   thesis.txt                       682048 bytes

LPRM - cancel jobs

$ lprm    #cancel all user’s jobs
$ lprm 31   #cancel job 31 (thesis.txt) on the default printer.

LPC - controlling the lpd program with lpc

$ lpc 

By default, this enters you into an interactive mode, and you can begin issuing commands.

$ lpc status all

The lpc command-line arguments; any commands marked with ‘option’ can either be a printer name (lp, print, etc) or the keyword ‘all’, which means all printers

  • disable option - prevents any new printer job from being entered
  • down option - disables all printing on the printer
  • enable option - allow new jobs to enter the print queue
  • quit (or exit) - leave lpc
  • restart option - restarts lpd for that printer
  • status option - print status of printer
  • up option - enable everything and start a new lpd

The RedHat printtool (needs reworking)

Just a quick note here on RedHat's amazing printtool program. It seems to do everything that a magicfilter would do. RedHat already installs many of the programs to do the filtering. Here's how I have my printer set up under RH 4.0 with an HP LJ 4L connected to my parallel port (should be the same for other versions of RH as well).

Become root and fire up printtool (if you su'ed, you remembered to SETENV DISPLAY :0.0 and xhost +, right?)

Click "Add", and hit "OK" for a local printer.

Fill in the printer device (/dev/lp1 for me)

Fill in the input filter - Select a printer type, resolution, and paper size (ljet4, 300x300, and letter)

Hit "OK" all the way back, and restart the lpd.

Just like rolling an /etc/printcap file by hand, you can have multiple printer definitions for each physical printer. One for different paper sizes, resolutions, etc.

Next Previous Contents

lpadmin tools

This is mostly found on older SYS-V or UNIX systems

Create a printer (printer queue) with the destination printer IP

lpadmin -p printername -v socket:// -E

Verify to list all printers on a server

lpstat -s