0

Below is my code on linux that prints a PDF on a remote MACOS system.

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 

Here are the logs for a particular print 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 

The logs say that the print was successful and the return code was 0(successful).

But, the print actually failed, and below is the snapshot of the same.

Error: Gestoppt - Can't open "/private/var/spool/cups/d02183-001.

enter image description here

How can I refine my code so to make sure the print was actually successful?

Below is the lpstat -t logs:

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 
4
  • “Print successful” actually only means that the data was accepted by the print spooler. After that it gets sent to the printer, and if that fails, the error appears in logs but there's no convenient way to get it in a script. I think you have to obtain the job ID and poll its status. See unix.stackexchange.com/questions/62916/… for a similar problem (not an exact duplicate because that one was in python on linux, and sh on macos will make the answer slightly different).CommentedAug 2, 2021 at 20:10
  • @Gilles'SO-stopbeingevil' there are solutions for python but I still could not find any solution to check if my print was successful in shell scripting.
    – Ashar
    CommentedAug 3, 2021 at 4:51
  • Why do you ssh several times instead of running a more complex script in a single ssh session?CommentedAug 4, 2021 at 19:58
  • @Thorbjørn Ravn Andersen that approach can also be taken but my query is about how to detect a successful print in shell script.
    – Ashar
    CommentedAug 5, 2021 at 4:10

1 Answer 1

0

As said in the comments, the exit status of lp only shows that the job was successfully queued. The manual says that an exit status > 0 means "No output device was available, or an error occurred." (The "an error occurred" is a bit cryptic.)

A quick solution would be to use the output of ssh -p 3335 ibrahimince@localhost lpstat -t and parse that.

3
  • i m getting the following error ssh -p 3335 ibrahimince@localhost "lpstat -ot" lpstat: Invalid destination name in list "t". I tried ` ssh -p 3335 ibrahimince@localhost "lpstat -o -t" but this or any other command sometimes hangs !! and never returns.
    – Ashar
    CommentedAug 8, 2021 at 19:33
  • the -o was a typo; I meant lpstat -t. You could try other options (see man lpstat) if they give you a better idea of your printer status.CommentedAug 8, 2021 at 21:17
  • Dullalaart upon your suggestion i enabled lpstat -t and updating the output for the error seen in the log. I m however, not sure how can I determine which file failed to print and how can I resend the file for printing.
    – Ashar
    CommentedAug 24, 2021 at 17:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.