Working on a site with a few hundred OS X machines, manually altering each computer's configuration can become very tedious, very fast. Especially when dealing with printers. I had issues whereby I would sometimes need to set up a number of computers with a new printer, and then remove it later. Add to that, I have printers constantly spitting things out because people hit Print a few too many times and clog up the queues. Fortunately, I managed to come across a few Unix commands which, using ssh or ideally Apple Remote Desktop (via the ever-useful 'Send UNIX command' function), can reduce jobs of many minutes, even hours, into seconds.
Read on for some of the tricks I use...
Adding and Removing a Printer
This is done via the lpadmin command. To add a printer, use this format:
lpadmin -p Printer_Name -L "Printer Location" -E -v lpd://x.x.x.x
-P /Library/Printers/PPDs/Contents/Resources/en.lproj/Printer_Driver.gz
All you have to do to the above is adjust the settings as necessary. Unfortunately, the tradeoff here is that you can't use spaces in the Printer_name, tleast from what I can determine. "Printer location" can be anything. An IP address belongs in the x.x.x.x bit, and change lpd: to ipp: if that's what you use. I'm unsure about other protocols, but perhaps the man page can tell you much more about this command. Last of all is the driver. Before using the command, you'd be best to look in the directory shown and find the filename, and then replicate it in the command line. If you're lazy you could always just drag the PPD file over to the Terminal window, too!
lpadmin -x Printer_Name
Queue Management
lpstat -p
If you want to see the current jobs on a computer, simply use this command. (Note that this will show the jobs for the specified printer. However, if you do not specify a printer, it will show the jobs for all queues.)
lpstat -o Printer_Name
To clear a queue of all jobs, we use lprm. Note in this example the first hyphen is solo. This forces all jobs to be cleared; more methods to clear individual jobs or those of a particular are explained in the man page.
lprm - -P Printer_Name
Clearing all queues
#!/bin/bash
lpstat -p | awk '{print $2}' | while read printer
do
echo "Clearing Queue for Printer:" $printer
lprm - -P $printer
done
And that's that! Throw it at all of the computers under your wing, and hopefully you'll reduce waste, headache, and get to go home early for a change!
Mac OS X Hints
http://hints.macworld.com/article.php?story=20061203221317612