[英]How to dissect a CUPS job control file '/var/spool/cups/cNNNNNN'?
When printing a job to a CUPS server, you can set up the cupsd.conf parameters PreserveJobHistory
and PreserveJobFiles
to control how many jobs you want to keep.将作业打印到 CUPS 服务器时,您可以设置cupsd.conf参数PreserveJobHistory
和PreserveJobFiles
来控制要保留的作业数量。
CUPS always temporarily stores the actual print job files in directory /var/spool/cups/
. CUPS 总是将实际的打印作业文件临时存储在目录/var/spool/cups/
。 The spool files as submitted by the print client (before CUPS' conversion chain of filters kicks in) are always named dNNNNNN-001 (starting with a 'd' as in 'datafile') where NNNNNN is the job ID assigned by CUPS.打印客户端提交的假脱机文件(在 CUPS 的过滤器转换链启动之前)始终命名为dNNNNNN-001 (以 'd' 开头,如在 'datafile' 中),其中NNNNNN是 CUPS 分配的作业 ID。 If you submit a multi-document print job, the second document's spool file within the same job ID is named dNNNNNN-002 , and so on...如果您提交多文档打印作业,则同一作业 ID 内的第二个文档的假脱机文件名为dNNNNNN-002 ,依此类推...
Also, the same directory will hold files starting with another character, the control files and they will be named cNNNNNN for each job.此外,同一目录将保存以另一个字符开头的文件、控制文件,并且它们将为每个作业命名为cNNNNNN 。
I want to dissect these control files files.我想剖析这些控制文件文件。
When I use the strings
tool, it only reveals part of what I want to get at:当我使用strings
工具时,它只显示了我想要获得的部分内容:
Example:例子:
sudo strings /var/spool/cups/d00089
attributes-charset
utf-8H
attributes-natural-language
en-us
printer-uri
%ipp://localhost:631/printers/hp2B
job-originating-user-name
kurtpfeifleB
job-name
hosts!
copies
finishings
job-cancel-after
job-hold-until
no-hold!
job-priority
job-sheets
noneB
none!
number-up
job-uuid
-urn:uuid:ca854775-f721-34a5-57e0-b38b8fb0f4c8B
job-originating-host-name
localhost!
time-at-creation
time-at-processing
time-at-completed
job-id
job-state
job-state-reasons
processing-to-stop-point!
job-media-sheets-completed
job-printer-uri
(ipp://host13.local:631/printers/hp!
job-k-octets
document-format
text/plainA
job-printer-state-message
job-printer-state-reasons
none
Also, that strings
output doesn't look very nice.此外,该strings
输出看起来不太好。
Question: Is there a programmatic (or other) way to dissect these CUPS job control files and get at their complete content with all included info?问题:是否有一种编程(或其他)方式来剖析这些 CUPS 作业控制文件并获取其包含所有信息的完整内容?
Found an answer myself...自己找到了答案...
When you compile CUPS from sources, there is the subdirectory cups .当您从源代码编译 CUPS 时,会有子目录cups 。 It also holds a Makefile specific to this subdir.它还包含一个特定于该子目录的Makefile 。 That Makefile contains a build target named "unittests" which is NOT built by default!该 Makefile 包含一个名为“unittests”的构建目标,默认情况下它不是构建的!
But if you run make unittests
it not only runs its unit tests, but also creates a few command line utilities which potentially can be put to quite some good use outside of unit tests too!但是,如果您运行make unittests
它不仅会运行其单元测试,还会创建一些命令行实用程序,这些实用程序也可能在单元测试之外得到很好的使用!
For the case to solve my problem, it turns out that the testipp
CLI utility is pure gold.对于解决我的问题的案例,事实证明testipp
CLI 实用程序是纯金的。 See yourself:看看你自己:
sudo ./testipp /var/spool/cups/c00089
operation-attributes-tag:
attributes-charset (charset): utf-8
attributes-natural-language (naturalLanguage): en-us
job-attributes-tag:
printer-uri (uri): ipp://localhost:631/printers/hp
job-originating-user-name (nameWithoutLanguage): kurtpfeifle
job-name (nameWithoutLanguage): hosts
copies (integer): 1
finishings (enum): none
job-cancel-after (integer): 10800
job-hold-until (keyword): no-hold
job-priority (integer): 50
job-sheets (1setOf nameWithoutLanguage): none,none
number-up (integer): 1
job-uuid (uri): urn:uuid:ca854775-f721-34a5-57e0-b38b8fb0f4c8
job-originating-host-name (nameWithoutLanguage): localhost
time-at-creation (integer): 1472022731
time-at-processing (integer): 1472022731
time-at-completed (integer): 1472022732
job-id (integer): 89
job-state (enum): completed
job-state-reasons (keyword): processing-to-stop-point
job-media-sheets-completed (integer): 0
job-printer-uri (uri): ipp://host13.local:631/printers/hp
job-k-octets (integer): 1
document-format (mimeMediaType): text/plain
job-printer-state-message (textWithoutLanguage): Printing page 1, 4% complete.
job-printer-state-reasons (keyword): none
Unfortunately, running make install
will not install this tool into the system, and thusly it never gets exposed to any CUPS administrator!不幸的是,运行make install
不会将此工具安装到系统中,因此它永远不会暴露给任何 CUPS 管理员! Also, Linux distro packagers may easily overlook it.此外,Linux 发行版打包人员可能很容易忽略它。 testipp
runs under the radar for most CUPS geeks. testipp
运行在大多数 CUPS 极客的雷达之下。
There are a few more useful utilities built by make unittests
: make unittests
构建了一些更有用的实用程序:
These are: testadmin, testarray, testcache, testclient, testconflicts, testcreds, testcups, testdest, testfile, testgetdests, testhttp, testi18n, testlang, testoptions, testppd, testpwg, testraster, testsnmp
.它们是: testadmin, testarray, testcache, testclient, testconflicts, testcreds, testcups, testdest, testfile, testgetdests, testhttp, testi18n, testlang, testoptions, testppd, testpwg, testraster, testsnmp
。
Unfortunately, no Linux distro currently builds and ships these useful tools.不幸的是,目前没有 Linux 发行版构建和发布这些有用的工具。 So if you know a distro packager, please point him to this discovery here and ask her to package a nice bundle for all end-users of cups-test-utils.rpm
, or cups-test-utils.deb
or cups-test-utils.tgz
or whatever the package name suffixes for his $distro are!因此,如果您认识发行版打包人员,请在此处向他指出这一发现,并请她为cups-test-utils.rpm
或cups-test-utils.deb
或cups-test-utils.tgz
所有最终用户打包一个不错的包cups-test-utils.tgz
或他的 $distro 的任何包名后缀! ` `
I had a similar issue - we needed the duration of jobs and discovered your thread.我有一个类似的问题 - 我们需要工作的持续时间并发现了你的线程。 testIPP worked fine so far, but I didn't want to compile cups just for these little neat tool and also I need it to integrate in other go based applications. testIPP 到目前为止运行良好,但我不想只为这些小巧的工具编译 cups,而且我还需要将其集成到其他基于 go 的应用程序中。
I've started to implement small CLI util in go which also can be used as library https://github.com/ui-kreinhard/go-cups-control-files我已经开始在 go 中实现小的 CLI util,它也可以用作库https://github.com/ui-kreinhard/go-cups-control-files
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.