We have some windows box on the network, and shared printers on them.
I've added them through the CUPS web interface, and all of them works like a charm, we can print to them by php:
exec('lp -d vasosamsung file.pdf');
Cool. I worte a Printer
class, what makes some validation before the print job ccould start.
The first thing what I check is the printer is exists:
lpstat -p vasosamsung
If it is not says, the destination is invalid, then yes, move on. And here comes the tricky part.
If the answer is idle, or printing, the everything is fine, let's send the job.
BUT!
The problem is it says, the printer is idle, because on my machine the printer has added to the list of printers, but sadly it is offline. This is what I want to catch. More problems come.
Ok, I can deal with it, the jobs are in the queue even if the printer itself is offline (pulled out from the machine).
The real problem is, that when I removed the whole printer thing from my "Printers and Devices" with right click and remove device, CUPS says, it is idle. I've restarted the CUPS by service cups restart
, and get a stat:
printer vasosamsung is idle. enabled since Thu 06 Apr 2017 03:34:26 PM CEST
It is not true. Now on my machine there is now printer like this. The worst thing, if I am send a document to it, it says:
string(40) "request id is vasosamsung-71 (1 file(s))"
and the job is on the web interface:
vasosamsung-71 Unknown Withheld 1933k 1 held since
Thu Apr 6 15:59:43 2017
My question is: is there a way ti get the phisicaly printer status? Offline, printing etc… not from CUPS?
If it is not possible, can I get somehow, is the printer is in the device list on the target machine at least?
EDIT
Hehe, when I turned off my machine, the printer is idle also 🙂
I guess, this is because vasosamsung printer is in the CUPS, and that is not the phiscal device, now I see, but my questions are still alives.
Best Answer
Use
lpstat
with the-t
parameter:The system tells us the printer is accepting requests, eg "Good to go".