The command interface to lp consists of a set of commands for users sending their jobs to the printer and a set of administrator commands for managing printer resources.
The lp spooling utility allows
The commands described in this section allow users on workstations and across the network to access the printing facilities. Users should use the lp and cancel commands most frequently, the lpstat command occasionally, and the enable and disable commands infrequently, if ever. No special privileges are necessary to use these commands.
This section describes the five basic lp commands.
The lp command routes a print job request to a destination where it is placed in a queue to await printing. The destination may be a single printer or a class of printers. If you do not specify a destination, the request is routed to the default destination. For information on how to set the default printer destination, see "Changing the Default Printer Destination".
The form of the lp command is
lp[options] filename...
Every time an lp request is made, a request ID is assigned to the job and a record of the request is sent to you. The request ID has this form:
destination-seqnum
destination is the printer or class of printers to which the job has been routed. seqnum is an arbitrary sequence number assigned to the job by the lp system.
lp has three options that are particularly useful: -n, -d, and -c.
lp -nnumber
number is the number of copies to print. Note that there is no space between -n and number.
lp -ddestination filename...
lp -c filename...
You can combine these command options in any order. For a complete list of lp options, see the lp(1) reference page. Example 2-1 and Example 2-2 show some uses of the lp command.
Example 2-1 : Simple lp Print Requests
lp myfile
lp < myfile
cat myfile | lp
To request a printout, you can use the lp command several different ways. The entries in Example 2-1 perform identical functions, sending a simple print request to the default printer.
Example 2-2 : Complex lp Print Request
lp -n3 -dfoo -c myfile
The entry in Example 2-2 prints three copies on printer foo and creates a copy of the file for the printer to process, ensuring that if changes are made to the file after the print request, the original file is printed.
The cancel command removes a job from the queue. You can cancel a job either before or after it starts printing.
Any user can cancel any other user's job. If you cancel another user's print request, mail is sent to that user. Once you cancel a job, you can request that it be printed again only with the lp command:
cancel printer-name
cancel request-ID...
Using the printer-name cancels the job currently being printed. Using the request-ID cancels the specified job(s) whether or not it is currently being printed, as shown in Example 2-3.
Example 2-3 : Using the cancel Command
cancel myprinterrequest "myprinter-16" cancelled
cancel myprinter-17request "myprinter-17" cancelled
Issuing a cancel command does not work when the job is being printed on a remote printer. To cancel a print job on a remote printer, log in to the remote system and issue the cancel command.
The lpstat command reports the status of various aspects of the lp system. To check lp status, type
lpstat [options]
Use the -t option to display a complete report on the status of the lp system.
For a complete list of options, see the lpstat(1) reference page.
Example 2-4 shows a sample lpstat -t command and its result:
Example 2-4 : Using the lpstat Command
lpstat -tscheduler is runningsystem default destination: myprintermembers of class foo:myprinterdevice for myprinter: /dev/plpmyprinter accepting requests since Jul 31 21:40foo accepting requests since Jul 30 12:23printer myprinter now printing foo-18enabled since Aug 5 15:34foo-18 mylogin 3156 Aug 7 17:11 on myprinter
This section summarizes the administrative commands that control the lp system. To execute administrative commands, you must be logged in as either root (that is, the superuser) or lp. Inexperienced users should not use the lp administrative commands.
The lpsched command starts the lp scheduler, the background daemon responsible for scheduling lp requests. lp prints jobs only when the scheduler is running on that system. lpsched is executed automatically each time the computer is booted.
Every time lpsched is executed, it creates a file called SCHEDLOCK in /var/spool/lp. When the scheduler is stopped under normal conditions, SCHEDLOCK is automatically removed. As long as this file exists, the system does not allow another lp scheduler process to run. If the scheduler stops abnormally (for example, if the system shuts down abnormally), you must remove SCHEDLOCK before you use the lpsched command.
To start the lp scheduler, type
/usr/lib/lpsched
There is no response from the system to acknowledge the lpsched command; to verify that the scheduler is running, use lpstat.
You can disable lpsched from starting at boot time using chkconfig(1M). The command
chkconfig lp off
prevents lpsched from running at system startup. To enable lpsched at system startup, enter
chkconfig lp on
The lpshut command stops the lp scheduler and ends all printing activity. All requests that are being printed when you issue the lpshut command are reprinted in their entirety when the scheduler is restarted.
To stop the lp scheduler, type
/usr/lib/lpshut
The disable command prevents the printer from printing jobs in the queue. Possible reasons for disabling the printer include malfunctioning hardware, paper jams, running out of paper, or end-of-day shutdowns. If a printer is busy at the time it is disabled, the request it was printing is reprinted in its entirety when you reenable the printer.
You can send job requests to a printer that has been disabled. The jobs are put in the queue but are not printed until the printer is enabled.
To disable a printer, type
disable[-c] [-r"reason"] printer(s)
The enable command permits a printer that has been disabled to begin printing jobs from the queue. Example 2-5 shows how to use the enable command. To enable a printer, type
enable printer...
Example 2-5 : Using the enable Command
disable -r"paper jam" myprinterprinter "myprinter" now disabled
enable myprinterprinter "myprinter" now enabled
The reject command stops lp from routing requests to a destination queue. For example, if a printer has been removed for repairs, or has received too many requests, you may wish to prevent new jobs from being queued at that destination.
If the printer is enabled, all requests that are in the queue when you issue the reject command are printed.
The reject command takes the form
/usr/lib/reject[-r"reason"] destination
Use the -r option to tell other users why print requests are being rejected. reason is a character string and is enclosed in double quotation marks (" "). This string is reported to anyone trying to use lp to send requests to the specified destination.
The accept command allows job requests to be placed in a queue at the named printer(s) or class(es) of printer(s). As shown in Example 2-6, accept allows a printer to receive job requests and reject disables printing:
Example 2-6 : Using the accept and reject Commands
/usr/lib/accept myprinterdestination "myprinter" now accepting requests
/usr/lib/reject -r"printer broken" myprinterdestination "myprinter" is no longer accepting requests
The lpmove command moves print requests from one destination to another. For example, if you have a printer removed for repairs, you may want to move all jobs pending on the queue to a destination with a working printer. You may also use lpmove to move specific requests from one destination to another but only after you have halted the scheduler with the lpshut command. lpmove automatically rejects job requests rerouted to a destination without a printer. The lpmove command takes two forms:
/usr/lib/lpmovedest1 dest2
/usr/lib/lpmoverequest(s) destination
dest1, dest2, and destination are printers or classes of printers. request is a specific request ID.
In the first form of the command, all requests are moved from dest1 to dest2. After the move, the printer or printers at dest1 does not accept requests until you issue an accept command. All rerouted requests are renamed dest2-nnn, where nnn is a new sequence number in the queue for destination dest2. In the second form, which you can issue only after you stop the scheduler, the rerouted requests are renamed destination-nnn. When you restart the scheduler, the original destinations still accept new requests. Example 2-7 demonstrates the use of the lpmove and lpshut commands.
Example 2-7 : Using the lpmove and lpshut Commands
/usr/lib/lpmove myprinter yourprinter
lpshut
/usr/lib/lpmove foo-19 foo-20 yourprintertotal of 2 requests moved to yourprinter
The lpadmin command has two primary uses:
Unlike most IRIX commands, lpadmin requires an option. The lpadmin command takes three forms:
lpadmin -ddestination
lpadmin -xdestination
lpadmin -pprinter[options]
You cannot remove a destination (printer or class) if it has pending requests; you must first either remove all requests with the cancel command or move them to other destinations with lpmove.
Removing the last remaining member of a class deletes that class from lp. Removal of a class, however, does not imply the removal of printers assigned to that class.
Note: The rmprinter command can also be used to remove a printer. See "Removing a Printer".
lpadmin -pprinter [-cclass] [-rclass]
The -p option does not work while the scheduler is running.
In Example 2-8, the first entry shuts down the lp scheduler. The second entry removes the printer myprinter from the lp spooling system. The printer myprinter is then removed from the foo class and assigned to the boo class with the third entry.
Example 2-8 : Using the lpadmin Command
/usr/lib/lpshut
/usr/lib/lpadmin -xmyprinter
/usr/lib/lpadmin -pmyprinter -rfoo -cboo
For a complete list of options, see the lpadmin(1M) reference page.