Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 . . .
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.
Prepend tea4cups:// to the desired DeviceURI in /etc/cups/printers.conf to enable tea4cups on that device.
Create the directory /etc/cups/tea4cups.d
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.