Help with adding shared printers via terminal

Hello, I'm very familiar with adding printers via the command line:

lpadmin -p queue name -v ipp://172.xx.xx.xx -E -D "description" -L "location" -m everywhere (or ppd file)

However, I have a lab of iMacs at my school which have traditionally connected to a dedicated "printer server" iMac, which has 4 high quality Epson Ink Jets connected via USB and shared through Printer Sharing preferences. Well, something changed recently on the network and it's broken all installs of the printers and now we have to manually re-install these individually. I'd like to be able to simply use the lpadmin command that I already know to be able to re-install these printers, but they don't individually have IP addresses, so I'm stuck trying to get them to install via the printer server iMac.


How do I address the printers for use with the lpadmin command? I've discovered that running

lpinfo -v

shows me a very comprehensive list of all the printers being broadcast on my subnet, and I can find the printers listed here as with a very long dnssd address:

dnssd://NAME%20OF%20PRINTER._ipp._tcp.local./?uuid=A1ABC5D6-9870-4EC8-80BE-A8A0F 68A662B

I was hoping that I could simply copy this address and use it for my device_uri, but it doesn't work. If I use the "everywhere" model, then it fails saying it can't find the file and if I point it directly at the PPD, it installs, but there's no communication to the printer from the new print queue.


Can anyone please point me on the right path to being able to programmatically add printers to Macs that are being shared via bonjour?


Thanks!

MacBook, macOS High Sierra (10.13.4)

Posted on Sep 28, 2018 11:37 AM

Reply

Similar questions

19 replies

Oct 10, 2018 9:59 AM in response to tzmmtz

No doubt! This was a head-scratcher for me. But this is what I did to get things working:


First, look for the addresses of the printers on your network using this command:

lpinfo -v

You will see the long address of the printer you're looking to install, it will look something like this:

dnssd://NAME%20OF%20PRINTER._ipp._tcp.local./?uuid=A1ABC5D6-9870-4EC8-80BE-A8A0F

Copy the address right up to the end of ._tcp.local. (no need to include the slash or anything after it).


Next, do a preliminary manual install of the printer you need, using the System Preferences. Once the printer is installed, navigate to the directory /etc/cups/ppd and find the .ppd file for the printer you'd just installed. Save that somewhere that it can be recalled by your command (mine is hosted on a web server and downloaded using the curl command prior to install).


Then, the command you need to execute the install will look like this:

lpadmin -p name-your-printer -v dnssd://NAME%20OF%20PRINTER._ipps._tcp.local. -E -D "Description of Printer" -L "Location of Printer" -P "/ppd_location/NAME_OF_PRINTER.ppd" -o printer-is-shared=false


For reference, this is what my full script looks like:

if [ ! $(lpstat -p | awk '{print $2}' | grep name-of-printer) ]; then

curl -s -o '/ppd_location/NAME_OF_PRINTER.ppd' 'http://ourwebserver/ppds/NAME_OF_PRINTER.ppd'

lpadmin -p name-of-printer -v dnssd://NAME%20OF%20PRINTER._ipps._tcp.local. -E -D "Description of Printer" -L "Location of Printer" -P "/ppd_location/NAME_OF_PRINTER.ppd" -o printer-is-shared=false

echo "NAME OF PRINTER was installed"

fi


Hope this helps you!

Oct 10, 2018 1:52 PM in response to tzmmtz

The PPD will have to be readable by the CUPS software—owner and access—and it's not common for that to be in a user directory.


Prolly under /Library/Printers/PPDs/Contents/Resources


For ownership and protection, sudo chown root:admin and sudo chmod s=rw,go=r the file, and an ls -ale should then look like the other files in the directory.


As an alternative, try with and the IP address, or with lpd and the IP address, and not the dnssd path.


Maybe something like this (single line) command (using ipp and not dnssd), once the PPD is relocated and its ownership and access settings adjusted.


lpadmin -p Canon_C5550_Back -v ipp://192.168.41.7 -E -D "Canon C5550 Back" -L "Center of the Pentagon Coffee Station" -P /Library/Printers/PPDs/Contents/Resources/C5550.ppd


This assumes the printer is at a fixed IP address.


The -L location is a display field and not an IP address FWIW, so quote any string here that contains spaces or ilk.


I'd recommend getting a DNS translation configured for that 192.168.41.7 address and using that, as hard-coded IP addresses tend to get messy.

Oct 10, 2018 10:47 AM in response to tzmmtz

Hi Todd, your command may be missing some quotes. I'd also recommend looking at the man page for lpadmin to better understand your options. But in summary:


-p = you choose this name which will be listed in CUPS (make sure there are no spaces)

-v = the only really important address that the command needs to find the printer

-E = simply enables the printer after setup

-D = Description... this is the name by which the printer is shown in the Print Dialog for the end user (use quotes here if there are spaces)

-L = A secondary Description, usually a physical location, but sometimes I use the IP address since the physical location is often already the name of the printer for us (i.e. "Office Printer" - use quotes here too if there are spaces)

-P = you need to include the path the ppd file you captured earlier and placed on your desktop


I would expect your command to work like this:

lpadmin -p Canon-C5550-Back-@-Print-Server -v dnssd://Canon%207565%20Front%20%40%20Print%20Server._ipp._tcp.local. -E -D 'Canon C5550 Back Printer' -L 'Back of Main Office' -P /Users/Foo/Desktop/Cannon\ C5550.ppd

You can escape spaces with the backslash "\" like I did for your .ppd file in the example. Or you can use quotes around the entire string like in the Description.


Hope this helps!

Oct 10, 2018 1:35 PM in response to tzmmtz

Have you checked permissions of the PPD? You said you copied the file from the print server, is it possible that user account logged into terminal doesn't have permissions over the file on the it desktop? If you're using ARD, be sure to "Run command as" and select "User" and type "root" and maybe that will help?


Good luck!

Oct 10, 2018 4:37 PM in response to tzmmtz

I've a whole pile of Brother and HP printer-related files sitting in that /Library/Printers/PPDs/Contents/Resources directory on a High Sierra box I just checked.


That's /Library/Printers/PPDs/Contents/Resources and not ./Library/Printers/PPDs/Contents/Resources, too. Dots matter.


Having the PPD anywhere other than on the system where the lpadmin command is invoked will not work. That storage might be remotely mounted or otherwise, but the PPD has to be accessible to CUPS.

Oct 11, 2018 8:26 AM in response to tzmmtz

Sorry for the web server confusion. I simply meant that my script pulls the ppd from there and copies it into the /tmp/ directory prior to installation. It's from a local directory that the lpadmin command will install the printer and place the ppd in the /etc/cups/ppd/ directory. It also installs as root, all with root permissions. However, when I first tested this, I successfully installed the printer after pointing it to a ppd placed on the Desktop, so I didn't think this was much concern.


Also... I may have incorrectly assumed you meant that your printer didn't have it's own IP address. If your printer does have it's own IP, then, unquestionably, the preferred method would be to connect directly as MrHoffman suggested. You can also use -m instead of -P and give it the "everywhere" argument to do it's own query for the right driver.


My original issue was that I couldn't get lpadmin to work with a printer that didn't have it's own IP address, as it was connected via USB and shared by an iMac using printer sharing.


I recommend still trying to figure this out, even if you've already done all 40 computers. Once you get the script working once, save it somewhere and you'll always be able to manage printers remotely any time there's a printer change, or if you want it to auto-reinstall if a user deletes it, etc.

Oct 10, 2018 10:23 AM in response to atoss

Thanks Atoss for the quick reply. Still a bit confused but am I on the right path here??

lpadmin -p Canon-C5550-Back-@-Print Server -v dnssd://Canon%207565%20Front%20%40%20Print%20Server._ipp._tcp.local. -E -D Canon C5550 Back Printer - L 192.168.41.6 -P


Is Location of Printer the IP # of the printer or is it the IP of our Print Server?


ppd location…. I just dragged the ppd from the printer server to the desktop of the computer I am using ARD and was going to use that desktop path instead of the curl command.


Todd

Oct 10, 2018 12:50 PM in response to atoss

Well....I've tried various attempts altering the code but it always comes back with.....


lpadmin: Unable to open PPD “/Users/it/Desktop/C5550.ppd”: Unable to open PPD file on line 0.

lpadmin: Unable to open PPD file “/Users/it/Desktop/C5550.ppd” - No such file or directory


Probably by now I could have done it all manually. Wish I knew terminal better.


This was my latest attempt that failed...

lpadmin -p Canon_C5550_Back -v dnssd://Canon%20C5550%20Back%20%40%20Print%20Server._ipp._tcp.local. -E -D 'Canon C5550 Back' -L 192.168.41.7 -P /Users/it/Desktop/C5550.ppd


Todd

Oct 10, 2018 2:26 PM in response to MrHoffman

Thanks but nothing works. Same error.


Tried putting it on our webserver as well and linking by an http address. Made sure permissions are correct. Same error.


Appreciate all you help. You have gone above and beyond helping me.


There comes a point, which is now, that I could have gone around by foot and finished 40 computers manually. Would have been good to know for the future but this one I can't figure out. I'm sure I am doing something wrong but have no idea at this point.


Best,

Todd

Oct 10, 2018 4:01 PM in response to MrHoffman

I only tried it once from our webserver as Atoss mentioned it was part of his script in the beginning of this discussion.


99% of the attempts I tried the ppd was local to where I was issuing the command from Apple Remote Desktop. Generally on the desktop. I also tried dropping it in ./Library/Printers/PPDs/Contents/Resources but that isn't where PPD's are stored anymore. Nevertheless I put it in their, set permissions and referenced that path but still same error.

Oct 11, 2018 4:41 PM in response to atoss

I manually added the printers for now going around to each one through ARD. When I have some spare time I'll try to get this working. Perhaps with my security consultant who is more versed in Terminal then I.


Thanks for all your help. We gave it a good try. It's probably something simple to fix in the string. I'll post back if I get this working.


Todd

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help with adding shared printers via terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.