![无法使用 ssh 检测远程系统上失败的打印](https://linux22.com/image/193874/%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8%20ssh%20%E6%A3%80%E6%B5%8B%E8%BF%9C%E7%A8%8B%E7%B3%BB%E7%BB%9F%E4%B8%8A%E5%A4%B1%E8%B4%A5%E7%9A%84%E6%89%93%E5%8D%B0.png)
下面是我在 Linux 上的代码,用于在远程 MACOS 系统上打印 PDF。
echo "Printing ssh -p 3335 ibrahimince@localhost 'lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE'";
echo "Remote File details are:"
ssh -p 3335 ibrahimince@localhost "ls -ltr $HOMEDIR/Printed/$NEWFILE"
until ssh -p 3335 ibrahimince@localhost "lp -o media=A5 -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE" >/home/system/efendibey.de/invoices/send4print/printererror.log 2>&1
do
echo "Exit Code of the command was: $?"
echo "Send email that there is an issue printing invoice for the below file. Issue is: `cat /home/system/efendibey.de/invoices/send4print/printererror.log`"
ls -ltr $FILE >>/home/system/efendibey.de/invoices/send4print/printererror.log
mail -s "PRINTER SERVICE FAIL ALERT. PLEASE CHECK YOUR PRINTER!!" [email protected] < /home/system/efendibey.de/invoices/send4print/mailbody.txt
sleep 20
done
echo "Print successful. Deleting $FILE"
rm $FILE;
fi
以下是特定打印的日志online_delivery_10001333.pdf
。
Printing ssh -p 3335 ibrahimince@localhost 'lp -d Brother_HL_L2350DW_series /Users/ibrahimince/Printed/online_delivery_10001333.pdf'
Remote File details are:
-rw-r--r-- 1 ibrahimince staff 11496 Aug 2 19:29 /Users/ibrahimince/Printed/online_delivery_10001333.pdf
Print successful. Deleting /home/system/efendibey.de/invoices/send4print/online_delivery_10001333.pdf
日志显示打印成功,返回码为0(成功)。
但是,打印实际上失败了,下面是相同的快照。
错误:Gestoppt - Can't open "/private/var/spool/cups/d02183-001.
如何改进我的代码以确保打印确实成功?
以下是lpstat -t
日志:
Remote File details are:
-rw-r--r-- 1 ibrahimince staff 11507 Aug 18 20:00 /Users/ibrahimince/Printed/online_delivery_10001333.pdf
scheduler is running
system default destination: Brother_HL_L2350DW_series
device for Brother_HL_L2350DW_series: dnssd://Brother%20HL-L2350DW%20series._ipp._tcp.local./?uuid=e3248000-80ce-11db-8000-2c6fc95df52e
device for Brother_MFC_L3750CDW_series_b_3_Fax: dnssd://Brother%20MFC-L3750CDW%20series._ipp._tcp.local./?uuid=e3248000-80ce-11db-8000-3c2af4dd8a75
device for Canon_TS700_series: ippusb://Canon%20TS700%20series._ipp._tcp.local./?uuid=00000000-0000-1000-8000-00186d1376d5
device for Kyocera_ECOSYS_M5526cdw: dnssd://Kyocera%20ECOSYS%20M5526cdw._ipps._tcp.local./?uuid=4509a320-00a6-0073-00bb-002507512ad9
device for Kyocera_ECOSYS_M5526cdw_b_3_Fax: dnssd://Kyocera%20ECOSYS%20M5526cdw._ipps._tcp.local./?uuid=4509a320-00a6-0073-00bb-002507512ad9
Brother_HL_L2350DW_series accepting requests since Wed Aug 18 20:00:24 2021
Brother_MFC_L3750CDW_series_b_3_Fax accepting requests since Tue Jun 29 17:04:09 2021
Canon_TS700_series accepting requests since Wed Aug 18 18:34:42 2021
Kyocera_ECOSYS_M5526cdw accepting requests since Thu Jul 8 12:30:45 2021
Kyocera_ECOSYS_M5526cdw_b_3_Fax accepting requests since Thu Jul 8 12:28:58 2021
printer Brother_HL_L2350DW_series is idle. enabled since Wed Aug 18 20:00:24 2021
Can't open "/private/var/spool/cups/d03050-001."
printer Brother_MFC_L3750CDW_series_b_3_Fax is idle. enabled since Tue Jun 29 17:04:09 2021
printer Canon_TS700_series is idle. enabled since Wed Aug 18 18:34:42 2021
printer Kyocera_ECOSYS_M5526cdw disabled since Thu Jul 8 12:30:45 2021 -
reason unknown
printer Kyocera_ECOSYS_M5526cdw_b_3_Fax is idle. enabled since Thu Jul 8 12:28:58 2021
Brother_HL_L2350DW_series-3050 ibrahimince 12288 Wed Aug 18 20:00:24 2021
Print successful. Deleting
答案1
正如评论中所说,退出状态lp
仅表明作业已成功排队。手册说退出状态 > 0 表示“没有可用的输出设备,或发生错误”。 (“发生错误”有点神秘。)
一个快速的解决方案是使用ssh -p 3335 ibrahimince@localhost lpstat -t
并解析它的输出。