0

My question was marked as duplicate: But I have not seen any solution in combination with the IF sattement I am trying to use. Any hints are welcome. Thanks


I am currently creating a small bash script to convert PDF documents to a searchable PDF via OCR. For that I am using "ocrmypdf"

My goal is to move the original PDF to a directory called "processed" in case everything is ok and in case of error to an "error" directory. -> this part of my script is working

To get the OK or ERROR I added the command execution to a IF statement.

Remark: the "echo_log" is a function that adds the passed text message to a LOG file.

  if ocrmypdf $pdf_source $file
  then
    echo_log "OK OCR processing OK, move original file $pdf_source to $original_dir"
    mv $pdf_source $original_dir
  else
    echo_log "ERROR OCR processing FAILED, move original file $pdf_source to $error_dir"
    echo_log "ERROR Return values OCR process: $ret"
    mv $pdf_source $error_dir
  fi # OCR PDF/A Konvertierung

This is working fine so far, but I also like to add the error text of the executed command ocrmypdf to a variable to be able to store it within my logfile. How can I achieve this? At the moment the error text is just visible on the console.

Example of error text: ERROR - 1: page already has text! \u2013 aborting (use --force-ocr to force OCR) ERROR - 1: page already has text! \u2013 aborting (use --force-ocr to force OCR)

Thanks a lot Minxer

5
  • Hi tripleee,thanks a lot for the hint. But how does this work in combination with the IF statement I am using? Commented Feb 11, 2018 at 15:45
  • Try this: if VAR=$((ocrmypdf $pdf_source $file) 2>&1) because the return code of the assignment will be the return code of the last command executed. Commented Feb 11, 2018 at 16:16
  • @tripleee: this question was not an exact duplicate. Commented Feb 11, 2018 at 16:18
  • @Pierre François: Thank you very much for the tip. This is exactly what I was looking for. It works perfectly. Thanks a lot. Commented Feb 11, 2018 at 17:36
  • I posted another answer to the duplicate now. Commented Feb 11, 2018 at 18:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.