LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Hackish way to get number of pages printed by CUPS? (https://www.linuxquestions.org/questions/linux-server-73/hackish-way-to-get-number-of-pages-printed-by-cups-4175600078/)

summersab 02-18-2017 12:21 PM

Hackish way to get number of pages printed by CUPS?
 
I have a RPi connected to a Zebra label printer. The labels come on rolls of 320, and it's a real pain to submit a job only to have run out of labels in the middle. I'm trying to hack together a way to show a total number of pages printed that I can reset once I reload the printer with labels.

The web GUI for CUPS lets me show the completed jobs and accurately shows the number of pages printed. It seems like the lpstat command is generating this information and pulling from the /var/spool/cups files, but for the life of me, I can't figure out the syntax of flags to use with lpstat which will also display the page count. It will show everything else including the job size, but I can't get it to spit out page count.

Once I manage to do this, I'm going to create some hacky little cron job and script to keep a total that I can then reset, but if anyone has a suggestion on a more elegant way to do this (i.e. how to trigger the script to run only after something is printed, how to publish this information to the CUPS web GUI, how to reset the info via the web GUI, how to send me an email when the pages printed reaches a certain level, etc), that would be great, but at the minimum, I'd just like to know how to get lpstat to show the page count that the web GUI displays.

Thanks!

business_kid 02-18-2017 01:22 PM

Cups is not great. I send it 100 repeats of a page; it sends the page, tells the printer '100 of those pls' and says ~'job done while the printer is hacking away.

I would script it with a 'print one page' on 1 line, and print with this script, incrementing a variable. If you write the variable it will persist over script runs, but try not to write too often.

michaelk 02-18-2017 03:21 PM

cups does have its limitations. Depends on your printer make/model for example HP uses a Printer Job Language (PJL) which is like a header that can send additional information with the print data like number of copies so cups is not actually sending the same data 100 times. Once the job leaves the queue cups is done until you print something else.

To get the web GUI to process the page count would require change to cups itself. The easiest hack would probably be to write a script to count the number of pages from the /var/spool/cups/page_log file(s). As far as I know there isn't a lpstat option for job page count.

summersab 02-18-2017 04:27 PM

I think you may be misunderstanding (and I wasn't very clear - I admit that). With my printer, the web GUI DOES show the number of pages printed for each job. However, I can't figure out how to get that information from the command prompt. Where is the web GUI getting that information (i.e. what command is running to generate the info that is then displayed on the page)? From what I can tell, it's running lpstat and grabbing the data from the /var/spool/cups files. There's no page count data stored in /var/spool/cups/page_log. Furthermore, the output and format of lpstat more closely matches what the web GUI shows. Any thoughts?

michaelk 02-18-2017 05:21 PM

The web server aka GUI is built into the cups daemon. The "GUI" is getting its data from the cups daemon as well as the lpstat. I have not looked at either source code to determine what data is actually being processed. There is a total page count for each job in the page_log.

https://www.cups.org/doc/man-cupsd-logs.html

summersab 02-18-2017 05:25 PM

Ohhhh - I was totally misreading the page_log. I didn't understand that there is an entry after every page completes. I just thought it was giving a numerical count. One of my last jobs was 74 pages, so I just saw it counting on each line with no subsequent jobs. Okay, got it.

Is there a way to have a script get triggered whenever CUPS processes a job?

summersab 02-18-2017 05:28 PM

tea4cups. Solution found. :)

michaelk 02-18-2017 05:30 PM

There you go...


All times are GMT -5. The time now is 05:13 PM.