【问题标题】:How to dissect a CUPS job control file '/var/spool/cups/cNNNNNN'?如何剖析 CUPS 作业控制文件“/var/spool/cups/cNNNNNN”?
【发布时间】:2018-12-08 23:37:20
【问题描述】:

将作业打印到 CUPS 服务器时,您可以将 cupsd.conf 参数 PreserveJobHistoryPreserveJobFiles 设置为控制你想保留多少工作。

CUPS 始终将实际打印作业文件临时存储在目录 /var/spool/cups/ 中。打印客户端提交的假脱机文件(在 CUPS 的过滤器转换链启动之前)始终命名为 dNNNNNN-001(以“数据文件”中的“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 作业控制文件并获得包含所有信息的完整内容?

【问题讨论】:

    标签: binaryfiles cups ipp-protocol


    【解决方案1】:

    自己找到了答案……

    当您从源代码编译 CUPS 时,会有子目录 cups。它还包含一个特定于该子目录的 Makefile。该 Makefile 包含一个名为 "unittests" 的构建目标,它是默认构建的!

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

    为了解决我的问题,事实证明 testipp CLI 实用程序是纯金。看看你自己:

    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 发行版打包程序可能很容易忽略它。 testipp 对大多数 CUPS 极客来说都是隐秘的。

    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 /em> 或 cups-test-utils.debcups-test-utils.tgz 或他的 $distro 的包名称后缀是什么! `

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题 - 我们需要工作的持续时间并发现了您的主题。到目前为止,testIPP 运行良好,但我不想只为这些小巧的工具编译 cups,我还需要将它集成到其他基于 go 的应用程序中。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-12
        • 2012-01-23
        • 1970-01-01
        • 2014-08-20
        • 1970-01-01
        • 2018-03-16
        • 2012-08-29
        • 1970-01-01
        相关资源
        最近更新 更多