我有一台连接到打印机的远程 Mac。
我使用讨论的“ssh 端口转发/隧道”从本地系统使用 ssh 远程触发 Mac 上的打印这里。
下面是我在本地系统上的代码,它触发lp
远程服务器上的打印机命令并检查它是否已成功打印。
until ssh -p 3334 remuser@localhost "lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE" >/home/system/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/send4print/printererror.log`"
ls -ltr $FILE >>/home/system/send4print/printererror.log
mail -s "PRINTER SERVICE FAIL ALERT. PLEASE CHECK YOUR PRINTER!!" [email protected] < /home/system/send4print/mailbody.txt
sleep 20
done
echo "Print successful. Deleting $FILE"
我在日志中打印了以下消息,表明打印成功。
nohup.out:Print successful. Deleting /home/system/send4print/online_delivery_10000656.pdf
然而,在检查远程 Mac OS 系统时,由于以下错误,打印失败。
online_delivery_10000656.pdf
Stopped - Can't open "/private/var/spool/cups/d12637-001"
随函附上该快照的快照。
我在这里需要一些帮助:
如果
Can't open "/private/var/spool/cups/d12637-001"
远程主机上出现此类故障;我希望本地脚本中的返回代码不成功,而目前,我得到0
纠正此错误
Can't open "/private/var/spool/cups/d12637-001"
,以便我可以重试打印并确保第二次打印。
答案1
正确捕获退出代码
首先,让我们用处理退出代码的方式来解决问题:
ssh -p 3334 remuser@localhost "lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE" >/home/system/send4print/printererror.log
SERVICE_EXIT_STATUS=$? # store the exit code
# mail if failed
if [ $SERVICE_EXIT_STATUS -ne 0 ];then
mail -s "PRINTER SERVICE FAIL ALERT. PLEASE CHECK YOUR PRINTER!!" [email protected] << /home/system/send4print/mailbody.txt # email when there is an error...
echo "$FILE is the culprit" >>/home/system/send4print/printererror.log # adding at end of file like in your original script the filename of the "culprit"
echo "Send email that there is an issue printing invoice for the below file. Issue is: `cat /home/system/send4print/printererror.log`" # printing like your original script the log
else
echo "Print successful. Deleting $FILE"
#this is where you may delete the file i guess?
fi;
until
按要求使用:
until ssh -p 3334 remuser@localhost "lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE" >/home/system/send4print/printererror.log &> /dev/null
SERVICE_EXIT_STATUS=$? # store the exit code
do
# mail if failed
if [ $SERVICE_EXIT_STATUS -ne 0 ];then
mail -s "PRINTER SERVICE FAIL ALERT. PLEASE CHECK YOUR PRINTER!!" [email protected] << /home/system/send4print/mailbody.txt # email when there is an error...
echo "$FILE is the culprit" >>/home/system/send4print/printererror.log # adding at end of file like in your original script the filename of the "culprit"
echo "Send email that there is an issue printing invoice for the below file. Issue is: `cat /home/system/send4print/printererror.log`" # printing like your original script the log
else
echo "Print successful. Deleting $FILE"
#this is where you may delete the file i guess?
fi;
done
这应该有效。虽然我没有打印机,但我确实测试了逻辑是否有效(据我所知)。
关于您的打印机错误
我没有打印机,也没有你的打印机品牌,但是,通过搜索,我发现了几篇与你的错误类似的帖子,其中一些是在 Mac 上(就像你提到的那样),还有一些:
ETC
本质上,有四种可能的修复/原因导致您出现此错误: