Author Topic: Two printers in bash  (Read 565 times)

Offline dougmack

  • Hero Member
  • *****
  • Posts: 980
Two printers in bash
« on: March 01, 2012, 10:25:08 PM »
I have two printers hooked up.  In the gui, I get asked which one I want to print to.  In the terminal, I just pipe to lp.  Somehow, one printer gets
selected, I don't know how it decides.  And suppose I would like to print to the other?  How?  I seem to remember seeing Unix commands lp1 or lp2 or
something similar.  That must exist here, but Googling doesn't answer the question.  (Most of the time, I am happy to print to the LaserJet, which
seems to be where two of my Linux installs do, as it happens, but in case the laser is down, for some reason, I'd like to be able to choose the other.)

Thanx for the info.  --doug

Blessed are the peacemakers...for they shall be shot at from both sides.  A. M. Greeley

Offline Archie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8590
  • Aurum nostrum non est aurum vulgi.
Re: Two printers in bash
« Reply #1 on: March 01, 2012, 10:59:54 PM »
Good examples here.
Since 2006 | LiCo 401868 | Bare Metal | What is necessary is never unwise. --Sarek, 2258.42


Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2440
  • Any Bugs in site?
Re: Two printers in bash
« Reply #2 on: March 04, 2012, 06:13:12 PM »
dougmack
If you want to work off the CUPS command line then for example:

Quote
lp -d Laserjet2300dn-PostScript-1 /usr/share/printer-testpages/testpage.asc


Laserjet2300dn-PostScript-1 = one of my printers, replace with your printers.

this should print a simple test page. 

I would recommend that you set one of your printers as default printer, that way you know which printer will be used when you don't specify the printer on the command line.  You also know that if you want to use the other printer, you then have to specify the printer on the command line.

To see if you have a default printer, post the result of:

Code: [Select]
lpstat -t
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen

Offline dougmack

  • Hero Member
  • *****
  • Posts: 980
Re: Two printers in bash
« Reply #3 on: March 04, 2012, 07:27:17 PM »
Here's the output.  At the moment, the LaserJet is default, but when I posted,  the Deskjet was default, but in BOTH cases, bash selected the LaserJet. (I determined the default from the KDE setup.) Meantime, the suggestion from Archie kind of  tells me how to get the DeskJet to print from the terminal.  I haven't actually tried it, but I will. 

lp[doug@Linux1 ~]$ lpstat -t
scheduler is running
system default destination: LaserJet
device for DeskJet: ipp://192.168.1.123:631/printers/DeskJet
device for LaserJet: ipp://192.168.1.123:631/printers/LaserJet
DeskJet accepting requests since Tue 28 Feb 2012 02:10:02 AM EST
LaserJet accepting requests since Tue 28 Feb 2012 02:10:02 AM EST
printer DeskJet is idle.  enabled since Tue 28 Feb 2012 02:10:02 AM EST
printer LaserJet is idle.  enabled since Tue 28 Feb 2012 02:10:02 AM EST
        Ready to print.

Is there a way to give the two printers a simple name in bash without the long input that Archie's information indicates?
That is, cat foo | lp1 or cat foo | lp2 ?

thanx, guys.
Blessed are the peacemakers...for they shall be shot at from both sides.  A. M. Greeley

Offline wedgetail

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 2440
  • Any Bugs in site?
Re: Two printers in bash
« Reply #4 on: March 05, 2012, 03:23:17 AM »
dougmack
Quote
lp[doug@Linux1 ~]$ lpstat -t
scheduler is running
system default destination: LaserJet  < --------------------------- shows present default printer
device for DeskJet: ipp://192.168.1.123:631/printers/DeskJet
device for LaserJet: ipp://192.168.1.123:631/printers/LaserJet
DeskJet accepting requests since Tue 28 Feb 2012 02:10:02 AM EST
LaserJet accepting requests since Tue 28 Feb 2012 02:10:02 AM EST
printer DeskJet is idle.  enabled since Tue 28 Feb 2012 02:10:02 AM EST
printer LaserJet is idle.  enabled since Tue 28 Feb 2012 02:10:02 AM EST
        Ready to print.


Since you work from bash/cli and above indicates you are using CUPS, here is how to set the default printer.  You have relatively short printer names and easy to remember?

Quote
[root@localhost ~]# lpadmin -d  DeskJet <----  Now the system default printer

Quote
[root@localhost ~]# lpadmin -d  Laserjet <----  Now the system default printer

Still this may not be to your taste so you can also use the CUPS web interface when you have brought that up in your browser do as follows:

Printers > select the printer to be default > click on Administration drop down field > Set As Server Default

Just to convince yourself, run the lpstat -t   :D

If you are familiar with the CUPS web interface, I recommend the use of above as it will prevent mistyping of printer name. As I use Opera I have the CUPS webinterface in the Speed Dial so getting to the setting only takes a moment, less than 5 seconds to set the default printer.

Regarding something like lp1 and lp2 I don't know.  

Since you show cat foo | lp1, this tells me you are in the directory where the file you want to print is, in this case you should get the same with: lp -d foo (where I am assuming that Deskjet is your default),  or  lp -d Laserjet foo where I am assuming you have chosen a temporary alternative printer (Laserjet)
« Last Edit: March 05, 2012, 03:31:50 AM by wedgetail »
32 bit: KDE (older) & various KDE-mini, ASUSTek P5P41D Rev X.0x, BIOS AMI0207 07/21/2009, "Pentium(R) Dual-Core CPU E5300 @ 2.60GHz", nVidia GeForce 9600 GT, 2x1GB Seagate Technology 1000528AS HDD
TV CompuPro VideoMate Vista E700 (not working in Linux), Acer X243HD LCD Screen