如何剖析 CUPS 作业控制文件 '/var/spool/cups/cNNNNNN'?



将作业打印到 CUPS 服务器时,可以设置cupsd.conf参数PreserveJobHistoryPreserveJobFiles来控制要保留的作业数量。

CUPS 始终将实际打印作业文件临时存储在目录/var/spool/cups/中。打印客户端提交的后台打印文件(在 CUPS 的过滤器转换链启动之前)始终命名为dNNNNNN-001(以"datafile"中的"d"开头),其中NNNNNN是 CUPS 分配的作业 ID。如果提交多文档打印作业,则同一作业 ID 中的第二个文档的后台打印文件名为dNNNNNN-002,依此类推...

此外,同一目录将保存以另一个字符开头的文件,即控制文件,并且每个作业的文件名为cNNNNNN

我想剖析这些控制文件文件。

当我使用strings工具时,它只显示了我想要获得的部分内容:

例:

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

此外,strings输出看起来不是很好。

问:是否有一种编程(或其他)方法来剖析这些 CUPS 作业控制文件并获取其包含的所有信息的完整内容?

自己找到了答案...

当你从源代码编译 CUPS 时,有子目录cups。它还保存特定于此子目录的生成文件。该 Makefile 包含一个名为"unittests">的构建目标,默认情况下不会构建!

但是如果你运行make unittests它不仅可以运行它的单元测试,还可以创建一些命令行实用程序,这些实用程序也可以在单元测试之外得到很好的利用!

对于解决我的问题的情况,事实证明testippCLI 实用程序是纯金的。看看你自己:

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

不幸的是,运行make install不会将此工具安装到系统中,因此它永远不会暴露给任何 CUPS 管理员!此外,Linux发行版打包者可能很容易忽略它。对于大多数CUPS极客来说testipp都在雷达下运行。

make unittests
构建了一些更有用的实用程序:这些是:testadmin, testarray, testcache, testclient, testconflicts, testcreds, testcups, testdest, testfile, testgetdests, testhttp, testi18n, testlang, testoptions, testppd, testpwg, testraster, testsnmp

不幸的是,目前没有Linux发行版构建和交付这些有用的工具。因此,如果您认识发行版打包者,请在此处指出他的这一发现,并要求她为所有cups-test-utils.rpm最终用户打包一个不错的捆绑包,或cups-test-utils.debcups-test-utils.tgz或任何软件包名称后缀为他的$distro! `

我有一个类似的问题 - 我们需要作业的持续时间并发现了您的线程。 到目前为止,testIPP 运行良好,但我不想只为这些整洁的小工具编译杯子,而且我需要它集成到其他基于 Go 的应用程序中。

我已经开始在go中实现小型CLI实用程序,它也可以用作库 https://github.com/ui-kreinhard/go-cups-control-files