LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-21-2017, 08:49 PM   #1
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 23

Rep: Reputation: Disabled
CUPS page count and alert


So, here's my setup. I have one of those older Zebra thermal label printers. It's hooked up to a RPi (nerd bragging moment: the RPi is actually inside the case and soldered to the board for power and USB - I made a classic printer fully wireless). I compiled and installed the Google Cloud Print driver so I could connect it to my shipping software.

Here's my question. Is there a way to get a page count or send an alert once the printer prints so many pages (which can then be reset)? It doesn't matter how - email, system alert via the network, or something.

It sounds trivial ("why don't you just count, moron?") but more than once, I've gotten busy, lost track of how many labels I've printed, and right in the middle of a job, the roll of labels runs out. If it were paper, it wouldn't be a huge issue since I could just add paper and pick up where I left off. However, Zebra has to be calibrated with the new roll, and the last label is just a flap. So, I lose track of which labels have been printed, which haven't, etc. Is there a built-in function or a script I could run? Yes, I could look at the logs on the admin web console and manually total it up, but there's gotta be a better way . . .
 
Old 03-22-2017, 02:58 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Glad to see the need bragging moment. A nerd of your status won't need spoonfeeding.:-)


Cups uses GS to handle the postscript. Why not count ghostscript invocations or instances?
 
Old 03-22-2017, 03:38 PM   #3
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 23

Original Poster
Rep: Reputation: Disabled
So, I don't need MUCH spoonfeeding, but I'm not a CUPS guru, so . . . how the heck would I do that?

My current approach (prior to seeing your reply - I just got this little nasty to work) is something like the following:
Code:
count=0
for i in `cat page_log.1 | cut -d ' ' -f 3 | sort -u`
	do
	((count+=`cat page_log.1 | cut -d ' ' -f 3,6 | grep $i | cut -d ' ' -f 2 | sort -n | tail -1`))
done
echo $count
Yeah, I can't say I'm immensely proud of this approach, but sometimes, duct tape does the trick. I plan on appending something to the logs to restart the counter after a certain number is reached so my script only counts up to that line in the log file. Then, I'll kluge some sort of alerting/emailing/something mechanism. If you have better thoughts, I'm 100% game.
 
Old 03-22-2017, 04:55 PM   #4
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 23

Original Poster
Rep: Reputation: Disabled
I'm seriously so tired and out of it lately that I forgot I asked this a month ago but moved on before implementing anything:
http://www.linuxquestions.org/questi...ps-4175600078/

So, now, it's just a simple tea4CUPS posthook that launches this script. Sorry to double-post - I'm losing my mind . . .
 
Old 03-22-2017, 09:33 PM   #5
summersab
LQ Newbie
 
Registered: Feb 2015
Posts: 23

Original Poster
Rep: Reputation: Disabled
Just for historical purposes, this is what I did.
  1. Install tea4cups.
  2. Prepend tea4cups:// to the desired DeviceURI in /etc/cups/printers.conf to enable tea4cups on that device.
  3. Create the directory /etc/cups/tea4cups.d
  4. Create a script in /etc/cups/tea4cups.d and make it executable (name it whatever you'd like). Make sure to edit the number in the if statement to adjust your desired threshhold for when the printer should submit an out of paper job.
    Code:
    #!/bin/bash
    
    count=0
    for i in `tac $(ls /var/log/cups/page_log* | grep -v .gz$) | sed '/OUTOFPAPER/Q' | cut -d ' ' -f 3 | sort -u`
            do
            #I always forget how to do math in bash. This throws errors, but it works just fine, so I just said "meh" and dumped the error to null. So, sue me.
            ((count+=`tac $(ls /var/log/cups/page_log* | grep -v .gz$) | cut -d ' ' -f 3,6 | grep $i | cut -d ' ' -f 2 | sort -n | tail -1`)) 2>/dev/null
    done
    
    #Edit the threshhold here
    if [ $count -gt 300 ]
            then
            echo -e 'Time to change the labels!\nThere have been' $count 'pages printed!' | lp -t "OUTOFPAPER" -d Zebra_LP2844
    fi
  5. Edit /etc/cups/tea4cups.conf and add the following line:
    Code:
    posthook_0 : run-parts /etc/cups/tea4cups.d

Now, when you print, this script will run after each job. It checks to see how many pages have been printed since the last OUTOFPRINTER job was submitted. If this number has reached the desired threshhold, a page is printed after the current job to inform the user that the paper needs to be changed.

So, not the most elegant solution, but it works, and I figured I'd share/document it for when I inevitably format this system and can't remember how I made this work.
 
Old 03-23-2017, 10:52 AM   #6
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
I have health issues ATM, so much innovation is low.
Anything that works is good for cups. The bar is low
 
  


Reply

Tags
cups, raspberrry pi



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
CUPS printing a test page or document over multiple pages - CUPS 1.5.4 Asjas SUSE / openSUSE 3 08-14-2015 02:17 AM
How to find page count in a document ooolongT Programming 9 04-20-2012 10:11 PM
CUPS print quota by page count per user leonard.kroll Linux - General 0 05-12-2011 01:56 PM
how to find PDF page count mfoley Programming 8 02-26-2009 02:55 PM

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

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

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
Open Source Consulting | Domain Registration