如何在 UNIX 上取消特定月份的打印作业

如何在 UNIX 上取消特定月份的打印作业

如何在 UNIX 上取消特定月份的打印作业,例如

sudo cancel -e printernames month 

这是我要处理的打印队列文本

EpsonP_URSB-4125    admingou       priority 0  Aug  9 14:49 on EpsonP_URSB
        o24683889.out                         3897 bytes
EpsonP_URSB-4126    admingou       priority 0  Aug  9 14:51
        o24683917.out                         3897 bytes
EpsonP_URSB-4168    admingou       priority 0  Aug  9 16:40
        o24685868.out                         3873 bytes
EpsonP_URSB-4169    admingou       priority 0  Aug  9 16:49
        o24686042.out                         3873 bytes
EpsonP_URSB-4594    admingou       priority 0  Aug 15 14:02
        o24728095.out                         3873 bytes
EpsonP_URSB-4795    admingou       priority 0  Aug 16 15:32
        o24739409.out                         3942 bytes
EpsonP_URSB-6877    admingou       priority 0  Sep  2 08:11
        o24866057.out                         3909 bytes
EpsonP_URSB-9143    admingou       priority 0  Sep 19 08:36
        o25011121.out                         3873 bytes
EpsonP_URSB-9144    admingou       priority 0  Sep 19 08:40
        o25011183.out                         3899 bytes
EpsonP_URSB-9146    admingou       priority 0  Sep 19 08:44
        o25011237.out                         3922 bytes
EpsonP_URSB-9153    admingou       priority 0  Sep 19 08:57
        o25011532.out                         3873 bytes
EpsonP_URSB-9154    admingou       priority 0  Sep 19 08:58
        o25011538.out                         4118 bytes
EpsonP_URSB-9155    admingou       priority 0  Sep 19 08:58
        o25011542.out                         3893 bytes
EpsonP_URSB-9158    admingou       priority 0  Sep 19 09:19
        o25011789.out                         3967 bytes
EpsonP_URSB-9159    admingou       priority 0  Sep 19 09:22
        o25011836.out                         3967 bytes
EpsonP_URSB-9160    admingou       priority 0  Sep 19 09:23
        o25011907.out                         4060 bytes
EpsonP_URSB-9161    admingou       priority 0  Sep 19 09:24
        o25011930.out                         4015 bytes

答案1

考虑打印机队列中的一行:

EpsonP_URSB-4126    admingou       priority 0  Aug  9 14:51

要匹配第五个字段,并取消第一个字段中的作业 ID:

printer_queue_command | awk -v month=Aug '$5 == month { print $1 }' | xargs -r echo cancel

您可能需要调整cancel命令以包含打印机队列。-r如果您的版本xargs不支持,请将其删除。-n1如果您必须cancel分别为每个作业发出命令,请添加。echo当您对输出满意时删除。

相关内容