LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-18-2017, 12:21 PM   #1
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 22

Rep: Reputation: Disabled
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!
 
Old 02-18-2017, 01:22 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,922

Rep: Reputation: 915Reputation: 915Reputation: 915Reputation: 915Reputation: 915Reputation: 915Reputation: 915Reputation: 915
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.
 
Old 02-18-2017, 03:21 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,099

Rep: Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185
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.
 
Old 02-18-2017, 04:27 PM   #4
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
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?
 
Old 02-18-2017, 05:21 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,099

Rep: Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185
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
 
Old 02-18-2017, 05:25 PM   #6
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
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?
 
Old 02-18-2017, 05:28 PM   #7
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
tea4cups. Solution found.
 
Old 02-18-2017, 05:30 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,099

Rep: Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185Reputation: 2185
There you go...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CentOS 6.2, USB printer, CUPS says printed successfully but page is not printed stase Linux - Desktop 5 07-03-2012 06:49 PM
Why are the 2nd and subsequent printed pages offset! ivorcox Linux - Hardware 0 09-07-2011 07:00 AM
CUPS not reporting number of pages technopasta Linux - Desktop 0 08-17-2006 11:51 PM
Printed pages are cut off Kethinov Debian 3 10-30-2004 06:32 PM
Sharing cups printer with netatalk - black pages being printed mackayr Linux - Networking 2 06-08-2004 10:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration