Score:0

How to monitor and copy CUPS spool data and copy files to run a script?

sd flag

Broad problem: access cups spool data as common user

In a store, at the sales desk, we have a software that generates bills as PDF files, which the cashier prints for the customers. I do not have access to the database where these PDF files are generated. However, I have written a parsing script (using pdftotext and awk) to convert them to .csv, which I can then use to collate per each products delivery type and warehouse to create picking lists.

I want to run a script on each bill as soon as it is printed, to send copies to the corresponding warehouses.

Preliminary plan:

After some googling, I thought to use incrond/incrontab (inotify) to monitor printer activity and trigger my own script to process each bill. At the following question I found info regarding the cups spool: Where does Cups keep print job information?, and at CUPS - output a copy of all print jobs as PDF, I found that the data in /var/spool/cups is stored "as is", ready to be copied and processed; but I do not know how to monitor this folder or copy the data out--I can only see it as superuser. I am running Debian 11. I am confused by the permissions problem, and don't know how to proceed.

Should I use incrond as root to monitor /var/spool/cups? And if so, how can I then copy new print jobs out to where my normal user can read them?

(Frame challenges welcome, even though I've kind of cottoned to this incrond business).

Score:2
br flag

There is a flaw in your approach since the file can be vanished while your script is running and this become unreliable. If you still want to stick to preliminary plan you should run your script from the same user CUPS is running. This is usually root, so yes, you should run it from root.

Better approach would be to modify the path for printed documents, like:

You can add a custom filter in ppd file, it will be a script that will convert printed file on the fly. Custom filters explained.

You can assign new printer, like PDF printer. All documents would be saved in the specified folder as PDF, so you can monitor that folder, copy it and then send to real printer via lp command.

You can also use specific backend like Tea4CUPS. This and some other approaches can be found here.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.