0

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).

Conrado
  • 103
  • 2

1 Answers1

2

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.

kab00m
  • 498
  • 3
  • 10