How to print both from the command line as well as through CUPS?

17,972

Solution 1

I have the same problem, if you always add permissions to the file lp0, you must edit the printer rules:

$ gksudo gedit /lib/udev/rules.d/70-printers.rules

add [, MODE="0666"]

The file contains:

ACTION=="add", ... KERNELL="lp*" ... , MODE="0666"

Solution 2

Open a web browser to http://localhost:631/ to configure CUPS. You should be able to print from the command line via echo "text" | lpr. Use lpstat -t to see all of CUPS' status information, lpstat -d to see the system's default printing destination, man lpstat for more, man lpr for specifying which printer.

All printing should go via CUPS - it manages queues, printers, ...

Solution 3

Why don't you use lpr to print form the command line? Like:

echo "text" > /tmp/someFileName
lpr -P YourPrinter /tmp/someFileName

It's a workaround, but should be an easy way to do what you want without changing some permissions...

Share:
17,972

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a printer that is being used for two purposes:

    • Printing of regular documents (Word, Internet pages, etc)
    • Direct printing from the command line (done by echo "text" > /dev/usb/lp0)

    This all worked fine in a previous version of Ubuntu. However, recently we upgraded to 11.10 and encountered a problem. First of all, the printers are not added to /dev/usb anymore. So I can not echo to this path, and am unable to achieve printing from the command line.

    After some hassle, I was able to find a workaround. This workaround was editing /etc/modprobe.d/blacklist-cup-usblp.conf. This file reads:

    # cups talks to the raw USB devices, so we need to blacklist usblp to avoid
    # grabbing them
    blacklist usblp
    

    After commenting this blacklisting, the device appears properly in /dev/usb, as lp0. I had a problem with the permissions of lp0, but this was solved by the answer from Luis Felipe Barrera Mora.

    However, I now have one major issue to resolve. After I commenting the blacklisting, the printer stopped working when printing from Word documents. This is logical, because I disable something that CUPS needs. So basically I now only have the option to either enable regular CUPS printing and no command line printing, or I have command line printing and no CUPS printing.

    UPDATE

    For completeness: I in fact have two printers connected at the same time. One is used to print both using CUPS and the command line. The other one - an Epson receipt printer - is only used for command line printing. I've spent many days trying to get it running using CUPS but this was not possible. However, this means that the lpr command will not solve the problem, because I can not get this second printer to function under CUPS. I really need to be both able to access /etc/dev/lp0 (or a similar path) AND print using CUPS at the same time.

    • Anonymous
      Anonymous over 12 years
      You can print from the console using the lp command.
  • polapainz
    polapainz over 12 years
    The problem is that one of the printers is not recognized by CUPS (this is a receipt printer), so I think it will not appear when using lpr. I will try this afternoon though.
  • user5950
    user5950 over 12 years
    Ah, ok. Did not get that point. But maybe it's possible to make it work with CUPS.
  • brobrobrobrobro
    brobrobrobrobro over 12 years
    You said that it is only one printer and it used to work with CUPS, yes? If that is the case, I would, as user155533, put everything back the way it originally was and use lpr. Otherwise, I'd edit your question so it is clearer what you need.
  • goo
    goo over 12 years
    You can add ANY printer (even serial port printers) via CUPS at http://localhost:631. You'll have to enter your username and password, but it's easy, and you can easily Modify the printer later.
  • goo
    goo over 12 years
  • polapainz
    polapainz over 12 years
    @zpletan: there are indeed two printers involved. One does and one does not work with CUPS. It did not matter for the original question but with these answers it does, so I'll update the question.
  • goo
    goo over 12 years
    Rather that flipflopping the permissions back and forth, I strongly suggest that you work to getting the receipt printer working with CUPS, and abandon the >/dev/lp0. CUPS gives you spooling, queueing, the ability to reprint jobs, and is the modern way to manage printers.
  • Chris Travers
    Chris Travers over 10 years
    Upvoted this answer because usually printing to the device itself is preferred in retail environments with receipt printers. The extra processing/queuing time is a real problem and cutting out CUPS can save a lot of people some hassle in waiting for the cashier. There are times you want to go through CUPS (when sharing the printer between apps or users) but not in the typical retail setting.
  • goo
    goo over 10 years
    I understand your problem now, @Chris. I did find a couple of sites with explanations that may lead you to a solution. One is for SUSE Linux, link but Linux == Linux. The other talks about using Samba for POS printers, link But, I don't see how you can use/manage the same printer with AND without CUPS at the same time. 2 printers, one with CUPS and one without seems doable (YMMV).