ThreadStates

Managing Printers from the Command Line

At work I manage several Mac labs, each of which has several printers. These printers occasionally have problems, as all printers do. Since the labs contain up to 24 computers and can be located in a different building, I need to be able to administer the printers remotely, via ssh or Apple Remote Desktop (ARD).

Note that since these are just CUPS tools, this will work in Linux, with slight modification to the pathnames.

Adding and Removing Printers

Printers can be added and removed using lpadmin which is used to configure cups printers and classes.

Add a Printer

lpadmin -p Printer_Name -L "Printer Location" -E -v lpd://ip.addr.of.printer \
-P /Library/Printers/PPDs/Contents/Resources/Printer_Driver.gz

Printer_Name is whatever name you want to give the printer. Printer Location is optional. You will have to supply the path to the correct PPD file for the printer. The location above is the default location for PPDs in OS X.

Remove a Printer

lpadmin -x Printer_Name

lpadmin has many options that I haven't gone into here; see man 8 lpadmin for more.

List Installed Printers

lpstat prints cups status information and can be used to list the printers installed on a computer. It provides the Printer_Name used by lpadmin in the above examples.

lpstat -p

This command gives the following output on my system:

$ lpstat -p
printer _192_168_1_134 is idle.  enabled since Thu Jan 15 18:44:13 2009
printer Brother_HL_1450_series is idle.  enabled since Thu Mar  5 10:06:42 2009
printer Dell_Laser_Printer_5210n is idle.  enabled since Mon Dec 22 11:27:58 2008
printer DesignJet_800PS is idle.  enabled since Fri Jan 23 11:34:47 2009
printer hp_color_LaserJet_3500__000E7FE9F218_ is idle.  enabled since Wed Feb 18 14:22:26 2009
printer HP_LaserJet_5100_Series is idle.  enabled since Fri Jan 23 12:12:29 2009

Working With Print Queues

lpstat is used to print cups status information. It can be used to manipulate a printer's queue.

List All Jobs In a Printer's Queue

lpstat -o Printer_Name

Omitting Printer_Name will list all jobs on all installed printers.

Deleting Jobs From a Queue

lprm is used to cancel print jobs. The following command will cancel one job.

lprm -P Printer_Name job_ID

If job_ID is replaced with - then all jobs will be canceled, clearing the queue.

I am able to solve most printer related problems remotely with the commands above. Of course they don't help when there is a networking or hardware related problem!

Note: Most of the above content was adapted for OS X 10.5 from an older macoshints article.