Usb printers take the same port deterministically?

Warren Block wblock at
Sun Jun 5 02:33:16 UTC 2011

On Sat, 4 Jun 2011, Scott Gasch wrote:

> Thanks, Warren.  Works great, mostly :)
> I actually need the "unlpt*" device because of publishing the raw printers.  Hooking the attach/detach of those device names directly did not work.  Adding an action to the "ulpt"
> device does work... but I then ran into the problem of pulling the number out of the $device variable to figure out what port just attached.  After some messing around (I tried to match
> the device and serial variables) I gave up and just made two entries per printer: one for ulpt0 and one for ulpt1 (see below).

"action" can be a whole script.  Of course the quoting can get ugly. 
Here's what I use for a scanner.  The backtick portion was from someone 
on the mailing lists.  Can't recall who came up with it, but they 
deserve credit anyway:

attach 20 {
         device-name "ugen[0-9].[0-9]";
         match "vendor" "0x04b8";
         match "product" "0x010a";
         action "usb_devaddr=`echo $device-name | sed 's#^ugen##'` && \
                 chown root:saned /dev/usb/${usb_devaddr}.* && \
                 chmod 0660 /dev/usb/${usb_devaddr}.* && \
                 su saned -c '/usr/local/bin/scanbuttond \
                 -s /usr/local/etc/scanbuttond/ \
                 -S /usr/local/etc/scanbuttond/ \
                 -b /usr/local/lib/'";

usb_devaddr is created by removing "ugen" from device-name.  Then it 
sets owner and permissions on the device and runs scanbuttond as user 

> Just because I'm a pain, how does this work if you have two printers 
> from the same vendor?  Epson's product code 0x0009, for example, means 
> "high speed usb 2.0 printer".  So I'm guessing, really, that any epson 
> printer would match?

Different models should have different product codes.  Failing that, 
there might be other information available, like a model number or 
serial number.

More information about the freebsd-questions mailing list